c# - HttpClient is adding it's own cookie header -
i have rather strange problem. questions on internet how add , cookies, want opposite ;)
when try send request via httphandler adding it's own cookie header. have rid of it. without digging details - when added, server trying request giving me wrong answer. works without cookie (tried in fiddler).
but problem, code:
string domain = "somemysteriousdomain"; var handler = new httpclienthandler(); handler.usedefaultcredentials = false; handler.allowautoredirect = true; handler.clientcertificateoptions = clientcertificateoption.manual; handler.usecookies = false; var httpclient = new httpclient(handler); var request = new httprequestmessage(httpmethod.get, domain); request.headers.useragent.add(new productinfoheadervalue("mozilla", "5.0")); request.headers.acceptencoding.add(new stringwithqualityheadervalue("gzip")); var response = await httpclient.sendasync(request);
raw request seen in fiddler:
get https://domain http/1.1 accept-encoding: gzip user-agent: mozilla/5.0 host: domain connection: keep-alive cookie: cadata477e7c1824f44800af0077724f65345="51595d316-0286-44bb-bc6f-ffb1fd311a92sqja36ra69yw7abg+ihxyi9lacbln6dbwe8a3mlejd2vcluo/uq5ef6f6t4nwh4nhdrcv4rea15hs0e2q6gatmac59uvbljhreydh6prbzzc/2qn8qhtpc6go5b56r"; mobile=0
i don't want add cookie! how delete/clear/whatever it? using visual studio community 2015, windows universal project. interesting, after rebooting pc after few hours, able make 2 or 3 requests without cookie (using same code) , mysterios cookie returned. about? how rid of it?
thank reporting issue - known issue system.net.http.httpclienthandler api implementation on windows 10 , working on fixing in upcoming release.
in meanwhile, possible workaround use windows.web.http.httpclient api underlying httpbaseprotocolfilter class. class has property called cookiemanager stores cookies each uri. can write method delete cookies cookiemanager destination uri before sending request. ensure no cookies sent. can see sample how delete cookies cookiemanager: https://github.com/microsoft/windows-universal-samples/tree/master/httpclient
thanks sidharth [msft]
Comments
Post a Comment