需要指定HttpRequestHeader.Cookies的格式? F.e,如果我想添加名为CITY的值为NY的cookie,我应该如何使用WebClient.Headers.Add()方法?
答案 0 :(得分:14)
试试这个样本
WebClient wb = new WebClient();
wb.Headers.Add(HttpRequestHeader.Cookie, "CITY=NY");
许多饼干:
wb.Headers.Add(HttpRequestHeader.Cookie, "cookiename1=cookievalue1; cookiename2=cookievalue2");
答案 1 :(得分:3)
要添加Cookie,最好也最容易使用Response.Cookies.Add();
HttpCookie myCookie = new HttpCookie("lastVisit");
myCookie.Value = DateTime.Now.ToString();
myCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(myCookie);
答案 2 :(得分:1)