HttpWebResponse and Cookies

T

Tom Jones

Hi,

I place an http request to a web server using HttpWebRequest. When the
response comes back (via a HttpWebResponse) the Cookies collection in the
response is empty, though if I scan through the response's Headers
collection I see that there *are* a number of "Set-Cookie" headers present.

Later on in the process I make another request (not to the same Uri though)
and the response DOES get its Cookies collection populated correctly.

Anyone have any idea what might be going on here?

Thanks,
tj
 
J

Joerg Jooss

Tom said:
Hi,

I place an http request to a web server using HttpWebRequest. When
the response comes back (via a HttpWebResponse) the Cookies
collection in the response is empty, though if I scan through the
response's Headers collection I see that there *are* a number of
"Set-Cookie" headers present.
Later on in the process I make another request (not to the same Uri
though) and the response DOES get its Cookies collection populated
correctly.
Anyone have any idea what might be going on here?

Can you provide some sample code or the site's URL where you don't get
cookies?

Cheers,
 
N

Nick Malik [Microsoft]

Can you post the Set-Cookie contents and the URL where the original request
is being made. The reason may be obvious once you look at the cookies
themselves. (Not every cookie should be sent back).

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
T

Tom Jones

Hi Nick,

[I also work at MS btw... ;-), Whidbey]

It looks like the main issue was that I was not allocating a new instance of
the CookieContainer and associating it with the *request*. As soon as I did
that, my responses had the expected cookie objects.

How do I determine if a cookie should be sent back or not?

Thanks,
-tj (not my real name)
 
N

Nick Malik [Microsoft]

Hello TJ,

Alas, if a cookie is in the container... send it back.
Cookies that don't go back are cookies that arrive expired. I've heard of
some interesting uses of expired cookies, especially from spyware.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Tom Jones said:
Hi Nick,

[I also work at MS btw... ;-), Whidbey]

It looks like the main issue was that I was not allocating a new instance of
the CookieContainer and associating it with the *request*. As soon as I did
that, my responses had the expected cookie objects.

How do I determine if a cookie should be sent back or not?

Thanks,
-tj (not my real name)

Nick Malik said:
Can you post the Set-Cookie contents and the URL where the original
request
is being made. The reason may be obvious once you look at the cookies
themselves. (Not every cookie should be sent back).

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top