HttpClient的是增加它自己的cookie头 [英] HttpClient is adding it's own cookie header

查看:170
本文介绍了HttpClient的是增加它自己的cookie头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很奇怪的问题。与所有的互联网问题如何添加和获取饼干,我想相反;)

I have rather strange problem. With all that questions over internet how to add and get cookies, I want the opposite ;)

当我尝试通过HttpHandler的是增加它自己的Cookie头部发送请求。我一定要摆脱它。没有挖掘到的细节 - 当添加它,服务器我想请求给我错误的答案。它的工作原理,而不该cookie(以小提琴手试过)

When I try to send request via HttpHandler it is adding it's own Cookie header. I have to get rid of it. Without digging into details - when it is added, server I am trying to request is giving me wrong answer. It works without this cookie (tried in fiddler).

但是,回到这个问题,代码:

But back to the 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



我不希望添加饼干!如何删除/清除/什么呢?
我使用Visual Studio 2015年的社区,与Windows通用项目。
有趣的是,几个小时后重新启动我的电脑后,我能够做2或3请求,而这个cookie(使用相同的代码),然后mysterios的cookie返回。
这是关于什么的?如何摆脱它

I don't want to add that cookie! How to delete/clear/whatever it? I am using Visual Studio Community 2015, with Windows Universal Project. What is interesting, after rebooting my pc after few hours, I was able to make 2 or 3 requests without this cookie (using THE SAME code) and then mysterios cookie returned. What it is about? How to get rid of it?

推荐答案

感谢您报告这个问题 - 这是一个已知的问题与System.Net。 Http.HttpClientHandler在Windows 10 API实现,我们就可以在即将发布的固定工作。

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

在此期间,可能的解决方法是使用Windows.Web。 Http.HttpClient与底层HttpBaseProtocolFilter类的API。这个类有一个名为CookieManager属性,存储每个URI所有的饼干。您可以编写发送请求之前删除从CookieManager饼干为目标URI的方法。这将确保没有饼干被发送。你可以看到这个样本如何从CookieManager删除cookies:的https:/ /github.com/Microsoft/Windows-universal-samples/tree/master/httpclient

In the meanwhile, a possible workaround is to use the Windows.Web.Http.HttpClient API with the underlying HttpBaseProtocolFilter class. This class has a property called CookieManager that stores all the cookies for each URI. You can write a method to delete the cookies from the CookieManager for the destination URI before sending a request. This will ensure that no cookies get sent. You can see this sample for how to delete cookies from the CookieManager: https://github.com/Microsoft/Windows-universal-samples/tree/master/httpclient

由于
Sidharth [MSFT]

Thanks Sidharth [MSFT]

这篇关于HttpClient的是增加它自己的cookie头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆