user3246814
user3246814

Reputation: 43

Passing cookies to httpwebrequest

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.

Upvotes: 1

Views: 4541

Answers (1)

CodeCaster
CodeCaster

Reputation: 151594

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"];

Upvotes: 2

Related Questions