Set cookie for all requests

Coordinator
May 23, 2012 at 3:38 PM

Hi -

Yes, you can do this but you'll need to create a custom WebLoadRequest.

1) Derive from WebLoadRequest

2) Override CreateWebRequest and follow these instructions: http://msdn.microsoft.com/en-us/library/dd920298(v=vs.95).aspx

Something like this:

 protected override HttpWebRequest CreateWebRequest() {
var hwr = base.CreateWebRequest();
hwr.CookieContainer = new CookieContainer();
hwr.CookieContainer.Add(new Uri("http://api.search.live.net"),
    	new Cookie("id", "1234"));

            return hwr;
        }

3) In your GetLoadRequest, just instantiate your derived class instead of WebLoadRequest.

 

Shawn