c# - HttpClient PostAsync does not respond when internet is disconnected -


i have xamarin forms app, app performs postasync call upload image multipartcontent.

the problem in ios device when switch off wifi/ mobile data during postasync call, httpclient doesnt go catch block indicate exception. after default timeout of 100 seconds.

however problem doesn't occur in android, , succesfully goes in catch block, indicating system.io.ioexception

this code performs postasync call, did miss or wrong. thank you.

 try{  multipartformdatacontent multipartcontent = new multipartformdatacontent();  var uri = new uri(string.format(strurl + "userdata/savepointrequestdata/", string.empty));   stringcontent strpointsrequestidcontent = new stringcontent(opointrequest.pointsrequestid.tostring());  multipartcontent.add(strpointsrequestidcontent, "strpointsrequestid");  if (bimagedata != null) {   var pointrequestfilecontent = new bytearraycontent(bimagedata);   pointrequestfilecontent.headers.contenttype = mediatypeheadervalue.parse("application/octet-stream");   pointrequestfilecontent.headers.contentdisposition = new contentdispositionheadervalue("form-data") {    filename = stractualimagename + ".jpg"   };   multipartcontent.add(pointrequestfilecontent, "struploadimage");  }   httpclient client = new httpclient();  httpresponsemessage response = await client.postasync(uri, multipartcontent);  if (response.issuccessstatuscode) {   using(var stream = await response.content.readasstreamasync()) {    using(var streamreader = new streamreader(stream)) {     var str = await streamreader.readtoendasync();     var obj = await jsonconvert.deserializeobjectasync < string > (str);     return obj;    }   }  } else {   return "error1" + "," + opointrequest.eventactivityname.tostring();  }  }  catch (exception ex) {   system.diagnostics.debug.writeline(e.message);     return "error2" + "," + opointrequest.eventactivityname.tostring();  } 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -