c# - HTTP POST stuck in an infinite loop until times out? -


i have sent post request using code:

var postdatax = new dictionary<string, string>                 {                     { "korefor", "new" },                     { "korename", "initial" },                     { "set_instant", "true" },                     { "set_engine", "google" },                     { "set_language", "en" },                     { "set_location", "uk" },                     { "set_mobile", "false" },                     { "set_email", "example@mediaworks.co.uk" },                     { "set_mainurl", "mediaworks.co.uk" },                     { "set_compurls", "google.com, yahoo.com" },                     { "koreforname", "mediaworks" },                     { "koreforkeywords", "newcastle seo, mediaworks, orm" }                 }; using (system.net.webclient wc = new system.net.webclient())     {         wc.headers.add("content-type", "application/x-www-form-urlencoded");         byte[] bytearrayx = system.text.encoding.ascii.getbytes(amend(postdatax));         byte[] byteresultx = wc.uploaddata("http://localhost:51378", "post", bytearrayx);         string responsex = encoding.ascii.getstring(byteresultx);     } 

when live , debugging gets stuck , loops until times out , crashes. i'm not sure why case.

the amend function:

private static string amend(dictionary<string, string> postdata) {     string amended = "";     foreach (var item in postdata)     {         amended += "&" + item.key + "=" + item.value;     }     return amended; } 

the line infinite loop triggers on:

byte[] byteresultx = wc.uploaddata("http://localhost:51378", "post", bytearrayx); 

any appreciated.

uploaddata not on infinite loop, it's blocking different.

uploaddata blocking, waiting until other side, server side http://localhost:51378 in scenario, respond it.

a long time blocking can occur because of following issues , other reasons well:

  1. when server busy other requests.
  2. server code taking long time process request.
  3. local or remote firewall issues.

webclient.uploaddata remarks msdn

the uploaddata method sends content of data server without encoding it. method blocks while uploading data. continue executing while waiting server's response, use 1 of uploaddataasync methods.

i'm recomend wrap uploaddata appropriate try..catch clause


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -