HttpClient adds custom cookie header

I have a rather strange problem. With all these questions on the internet how to add and receive cookies, I want the opposite;)

When I try to send a request through the HttpHandler it adds its own Cookie header. I have to get rid of him. Without going into details - when it is added, the server I am trying to query gives me the wrong answer. It works without this cookie (tried fiddling).

But back to the problem, the 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);

      

The unhandled request seen in the 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 to add this cookie! How do I uninstall / clear / whatever? I am using Visual Studio Community 2015 with Windows Universal Project. Interestingly, after restarting my computer after a few hours, I was able to make 2 or 3 requests without this cookie (using the THEOREM code) and then mysticios cookie returned. What is it about? How to get rid of it?

+3


source to share


1 answer


Thank you for reporting this issue - this is a known issue with the System.Net.Http.HttpClientHandler API implementation in Windows 10 and we are working to fix it in an upcoming release.

However, a possible workaround is to use the Windows.Web.Http.HttpClient API with the HttpBaseProtocolFilter base class. This class has a CookieManager property that stores all cookies for each URI. You can write a method to remove cookies from the CookieManager for the destination URI before submitting the request. This will ensure that cookies are sent. You can see this example of how to delete cookies from CookieManager: https://github.com/Microsoft/Windows-universal-samples/tree/master/httpclient



Thanks Siddhart [MSFT]

+2


source







All Articles