c# - HttpClient.PostAsJsonAsync throws TaskCanceledException -


i'm using httpclient.postasjsonasync , post never sent. i'm monitoring wireshark , nothing goes out.

i feel deadlocking in here can't figure out what. i've read this guide , followed still nothing. i've tried both configureawait(false), async, await, creating new task async method, call never returned , post never made.

public class requestdespacho     {      /*           several public properties     */     public async void makerequest()             {                 try                 {                                         var response = await requester.makepost("createticket/", this);                     switch (response.statuscode) //this line never reached                     {                         case httpstatuscode.ok:                             messagebox.show("ok");                             break;                         case httpstatuscode.forbidden:                             messagebox.show("forbidden");                             break;                         case httpstatuscode.badrequest:                             messagebox.show("bad request");                             break;                         case httpstatuscode.internalservererror:                             messagebox.show("internal server error");                             break;                     }                  }                 catch (exception e) //taskcanceled exception appears after while                 {                     messagebox.show(e.tostring());                 }              }     } public static class requester     {         private static readonly httpclient client;          static requester()         {             client = new httpclient()             {                 baseaddress = new uri("http://10.2.4.29:1234/"),                 defaultrequestheaders = {{"x-auth_token", "token1"}},                 timeout = new timespan(0, 0, 15)             };         }         public static async task<httpresponsemessage> makepost(string dir, object data)         {             return await client.postasjsonasync(dir, data);         }     } public partial class form1 : form {     private async void button3_click(object sender, eventargs e)         {             var image = file.readallbytes(@"g:\1.jpg");             requestdespacho req = new requestdespacho("av. monroe 2323", -34.557762, -58.459346, tipoevento.merodeo,                 "palio rojo", image); //my model, doesn't matter             await req.makerequest();         } } 

it network related issue. conected wifi usb board , problem solved. still got no idea blocked requests...since postman worked in visual studio didn't...but code allright.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -