.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;

 

posted on 2016-03-29 09:16  sjns  阅读(1512)  评论(0)    收藏  举报

导航