Csharp/C#教程:HttpClient PCL Cookie未应用于请求分享


HttpClient PCL Cookie未应用于请求

我正在使用.NET HttpClient for PCL(2.2.15)来跨Windows Phone 8,Windows 8和.NET 4.5的公共库。 但是,我没有看到cookie被应用于请求。

我正在使用以下代码设置HttpClient和HttpClientHandler。 HttpClient是包装类的属性。

CookieContainer = new CookieContainer(); var handler = new HttpClientHandler { AllowAutoRedirect = true, CookieContainer = CookieContainer, Credentials = client.CredentialCache, UseCookies = true, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip }; HttpClient = new HttpClient(handler, false); 

使用以下内容发送请求。

 var response = await HttpClient.SendAsync(httpRequestMessage); 

当我在Debug中单步执行时,我能够查看处理程序上的CookieContainer,并且能够看到我正在使用预期cookie进行反对的域的CookieContainer。

Cookie具有以下值:

后续请求大致为: https://staging3.api.com/api/v3/Itemshttps://staging3.api.com/api/v3/Items

我也尝试过自己设置cookie,但CookieContainer.GetCookieHeader(requestUri)返回一个空字符串。

附加信息:

如果我将requestUri修改为https://www.staging3.api.com/api/v3/Items我可以从CookieContainer.GetCookieHeader(requestUri)获取cookie头

上述就是C#学习教程:HttpClient PCL Cookie未应用于请求分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/955752.html

(0)
上一篇 2021年11月21日
下一篇 2021年11月21日

精彩推荐