c# - WebClient no response and exception -


using webclient call post api:

try {   var webclient = new webclient();    var result= webclient.uploadstring('http://wewe.com/name', {...})   //log1 } catch(exception ex) {   //log2 } 

sometime hit problem log1 , log2 not log. no response , exception after http call? reason why?

the webexception give answer. read message , inner exception.

example:

string uri = "http://www.myurl.com/post.php"; try {     using (webclient wc = new webclient())     {         wc.headers[httprequestheader.contenttype] = "application/x-www-form-urlencoded";         string htmlresult = wc.uploadstring(uri);     } catch (webexception webex) {             webresponse errresp = webex.response;             using (stream respstream = errresp.getresponsestream())             {                 streamreader reader = new streamreader(respstream);                 string text = reader.readtoend();             } } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -