Friday, 15 April 2011

c# - HttpClient fails with System.ArgumentException when using ClientCert -> Client cert not sent -



c# - HttpClient fails with System.ArgumentException when using ClientCert -> Client cert not sent -

i running issue using windows.web.http.httpclient, in windows phone app. working server requires client certificate. when phone call sendrequestasync() "system.argumentexception: value not fall within expected range."

i setting clientcertificate utilize via httpfilter object.

i running wireshark on server , able decrypt traffic via server key. in wireshark see tlsv1.2 server hello, certificate, certificate request packet, , server requests certificate issued same ca issued certificate passed. right after see certificate request packet, see client send fin, ack packet.

note 2 https requests. first http options request, , request see client certificate beingness passed (i http 200 response on one). when sec request http post failure. both utilize same code path sending request server.

any ideas on how can httpclient utilize certificate?

here code using:

ihttpfilter httpfilter = null; httprequestmessage requestmsg = null; httpresponsemessage responsemessage = null; httpclient client = null; seek { httpfilter = new httpbaseprotocolfilter(); httpfilter.automaticdecompression = true; httpfilter.clientcertificate = _mycertificate; httpfilter.allowautoredirect = true; client = new httpclient(httpfilter); requestmsg = new httprequestmessage(); requestmsg.requesturi = _uri; requestmsg.method = _httpmethod; if (_postdata != null && _postdata > 0) { var poststream = new memorystream(_postdata); requestmsg.content = new httpstreamcontent(poststream.asinputstream()); requestmsg.content.headers.add(headercontenttype, _contenttype); requestmsg.content.headers.add(headercontentlength, _contentlength.tostring()); } httpcompletionoption completionoption = httpcompletionoption.responsecontentread; requesttask = client.sendrequestasync(requestmsg, completionoption).astask(request.canceltokensource.token); responsemessage = await requesttask; // .. process response } catch(exception e) { // handle errors } { if (requestmsg != null) { requestmsg.dispose(); } if (responsemessage != null) { responsemessage.dispose(); } if (httpfilter != null) { httpfilter.dispose(); } if (client != null) { client.dispose(); } }

the issue ended beingness setting content-length. alter way set post info , seems work now:

if (_postdata != null && _postdata > 0) { requestmessage.content = new httpbuffercontent(request.postdata.asbuffer()); requestmessage.content.headers.add(headercontenttype, request.contenttype); }

c# ssl windows-phone-8.1

No comments:

Post a Comment