1

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user3246814
  • 43
  • 1
  • 5
  • `I dont have access to some object properties including HttpWebRequest.CookieContainer`. That's strange. `CookieContainer` is already around for a while. Which framework version are you using? – Sjips Dec 05 '14 at 11:17
  • The reason for not having access to this property is known to me. I am just looking for a different way to do it. Is it possible? – user3246814 Dec 05 '14 at 11:22
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 05 '14 at 11:47
  • 1
    Please show some code. How can we tell why you wouldn't have access to the properties? – John Saunders Dec 05 '14 at 11:47

1 Answers1

2

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"];
CodeCaster
  • 147,647
  • 23
  • 218
  • 272