用httpclient访问时,附带cookie信息

var url = "address";
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { })
{
    cookieContainer.Add(new Uri("youdomain"), new Cookie("cookieName", "cookieValue"));
    var result = client.GetStringAsync(url).Result;
    return Content(result);
}
posted @ 2015-01-05 10:37  czcz1024  阅读(289)  评论(0编辑  收藏  举报