HttpRequestHeader cookie format

In what format should I specify HttpRequestHeader.Cookies? Fe, if I want to add a cookie named CITY with a value of NY, how can I do this using the WebClient.Headers.Add () method?

+6
source share
3 answers

Try this sample

WebClient wb = new WebClient(); wb.Headers.Add(HttpRequestHeader.Cookie, "CITY=NY"); 

For many cookies:

 wb.Headers.Add(HttpRequestHeader.Cookie, "cookiename1=cookievalue1; cookiename2=cookievalue2"); 
+11
source

To add a cookie, it’s best and easiest to use Response.Cookies.Add();

 HttpCookie myCookie = new HttpCookie("lastVisit"); myCookie.Value = DateTime.Now.ToString(); myCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(myCookie); 
+2
source

Headers.Add :

  myWebHeaderCollection.Add("CITY","NY"); 

Here's what your Cookie header should look like at the end of rfc 6265 :

 Cookie: CITY=NY; 
+1
source

Source: https://habr.com/ru/post/925952/


All Articles