.net 中HttpClient 携带cookie传输
Posted sjns
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.net 中HttpClient 携带cookie传输相关的知识,希望对你有一定的参考价值。
CookieContainer cookieContainer = new CookieContainer(); Cookie cookie = new Cookie("username", "username"); cookie.Domain = Request.Url.Host; cookieContainer.Add(cookie); // 加入Cookie HttpClientHandler httpClientHandler = new HttpClientHandler() { CookieContainer = cookieContainer, AllowAutoRedirect = true, UseCookies = true }; HttpClient httpClient = new HttpClient(httpClientHandler); var resp = httpClient.GetAsync("http://localhost:8002/Public/Passport.aspx").Result;
以上是关于.net 中HttpClient 携带cookie传输的主要内容,如果未能解决你的问题,请参考以下文章
轻松把玩HttpClient之封装HttpClient工具类,携带Cookie的请求
在 .net 4.5 中尝试使用 HttpClient 使 cookie 无法响应