码迷,mamicode.com
首页 > Web开发 > 详细

.net 中HttpClient 携带cookie传输

时间:2016-03-29 10:08:24      阅读:949      评论:0      收藏:0      [点我收藏+]

标签:

 

            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传输

标签:

原文地址:http://www.cnblogs.com/sjns/p/5331723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!