.net 中HttpClient 携带cookie传输

时间:2022-11-20 18:14:32
            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;