GetResponse Cookies

tractorsouce

New member
Joined
Aug 2, 2007
Messages
4
Programming Experience
1-3
When I GetResponse() on my HttpWebRequest it doesn't pass any cookies in the GET. Is there a way I can make the response GET use the cookies I have in my CookieContainer?
 
HttpWebRequest.CookieContainer is Nothing by default, assign it a new CookieContainer before you get the response, for later requests assign the same instance again before getting the response.
 
I don't think I explained things well enough, my apologies. My HttpWebRequest is a POST request. I have cookies in the CookieContainer that travel fine with the POST. After that request I call the GetResponse() A session in a packet sniffer reveals that the GET the GetResponse() sends is cookie-less. I have loaded cookies into the response via Cookies.Add. They still don't get sent with the GET.
 
It is the request that holds the cookies in its CookieContainer and it must be holding these before you call GetResponse. There is no point in assigning cookies to the response, it's going nowhere. With the correct CookieContainer instance in place it will get any cookies automatically if you make subsequent requests, no need to copy cookies from the response manually.
 
Well, I set up a seperate HttpWebRequest as a GET request that actually sends cookies proper with the request and that worked for my purposes. I really can't see where you say the response is going nowhere. It is indeed reaching out to the web as a GET. How else would it retrieve data? We must be on two different wavelengths.
 
(HttpWebRequest).GetResponse() is where you execute the request, it's the request you configure, not the reply (response).
 
On second thought, is it a call to GetResponse().ResponseUri that is sending a GET to figure out the Uri? I think I'm being ignorant and once again apologize. Maybe I'll play with the code later to see what is doing what more clearly. :)
 
Back
Top