Passing cookies to httpwebrequest

4.4k views Asked by At

Is it possible to pass cookies to HttpWebRequest without using property HttpWebRequest.CookieContainer?

For some reasons, I don't have access to some object properties including HttpWebRequest.CookieContainer. I do have access to HttpWebRequest class and CookieContainer class.

1

There are 1 answers

0
CodeCaster On BEST ANSWER

I'm not sure why you would want to ignore the existence of an existing mechanism and reinvent the wheel, possibly including bugs solved by the existing implementation.

Setting cookies is trivial though:

request.Headers["Cookie"] = "foo=bar";

Just as reading them from the response:

string cookieHeader = response.Headers["Set-Cookie"];