c# - Why does HttpClient throw an exception when the request is successful? -


i'm using httpclient in context of web request send web request follows:

private async task sendmanagerinfoasync(uri baseuri, string accesstoken, object obj,     string apipath, httpmethod httpmethod) {     string authtoken = await getmanagerauthtoken(baseuri, accesstoken)         .configureawait(false);      string url = new uri(baseuri, apipath).absoluteuri;      var request = new httprequestmessage(httpmethod, url)     {         content = new stringcontent(jsonconvert.serializeobject(obj))     };     request.content.headers.contenttype = new mediatypeheadervalue("application/json");     request.headers.add("authorization", authtoken);      // whatever reason, throws taskcanceledexception.     var response = await m_httpclient.sendasync(request).configureawait(false);      response.ensuresuccessstatuscode(); } 

the request i'm tracking down http put. reason, code throws taskcanceledexception once reaches preset httpclient.timeout length, 30 seconds. however, when check recipient of request, see datastore always updated information i'd sent within 1 second of originating request.

i don't understand why or how httpclient instance throw exception when request successful. no cancellation token being requested. has ever seen behavior before?


* tagged question related akamai because can observe behavior when flip switch turning on akamai services server receiving request.

i ended inspecting apparently unsuccessful request sent httpclient , successful request sent chrome postman. httpclient default includes expect: 100-continue header in each request. disabled follows, , request started behaving again.

m_httpclient.defaultrequestheaders.expectcontinue = false; 

(i don't have answer why works, it's gotten me moving forward again moment.)


edit: appears works way because akamai strictly interprets rfc 2616 8.2.3, declares origin server, if receives request expect: 100-continue header,

  • must either respond 100 (continue) status , continue read input stream, or respond final status code

  • must not perform requested method if returns final status code

so akamai still waiting 100 response code, never gets, request times out, translates taskcanceledexception thrown httpclient.

i still don't know why httpclient.defaultrequestheaders.expectcontinue defaults true rather false, that's question day.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -