473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

HttpWebResponse and Cookies

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
Nov 16 '05 #1
4 5725
Tom Jones wrote:
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,

--
Joerg Jooss
www.joergjooss.de
ne**@joergjooss.de
Nov 16 '05 #2
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.
--
"Tom Jones" <to********@hotmail.com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
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

Nov 16 '05 #3
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 [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:BFcCd.321942$HA.82793@attbi_s01...
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.
--
"Tom Jones" <to********@hotmail.com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
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


Nov 16 '05 #4
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" <to********@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP10.phx.gbl...
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 [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:BFcCd.321942$HA.82793@attbi_s01...
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.
--
"Tom Jones" <to********@hotmail.com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
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



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael Evanchik | last post by:
Hello all, since i wanted to use ssl and its seems easy to do so with this object. Im trying to login to a webserver (aol) for this example. But for some reason, im packet sniffing with ethreal...
0
by: Prasanna Padmanabhan | last post by:
I get an empty CookieCollection when I do HttpWebResponse.Cookies. However HttpWebResponse.Headers returns the correct list of cookies (represented as a comma-separated string) in the reponse. ...
3
by: C# Learner | last post by:
The following code gets the *body* of an HTTP message: <code> response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(),...
1
by: Ravi | last post by:
Hi , i am trying to pass the same session Id to all the webrequest, but sometimes the response.cookies returns zero and sometimes one. is this to do something with cookies expire. In this sample...
3
by: Thaynann | last post by:
I ham tryin to access a website, the first time i send a GET to display the first page it displays the HTML code, but always with text "Enable Cookies In Your Browser", is there a way to have it...
1
by: Prasanna Padmanabhan | last post by:
I am writing a simple HTTP Client in .NET. I make an HTTP Request and examine the response. I get an empty CookieCollection when I do HttpWebResponse.Cookies. However HttpWebResponse.Headers...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
2
by: Mr Flibble | last post by:
Hey! I get a 404 from a website (this is "correct behaviour") and I'm interested in the value in the cookie "SMSESSION". The question is the following code generates an exception due to the...
2
by: GHS | last post by:
I have some code to connect to a website and pull some content out of the HTML. I've verified that the 2 URLs I'm using are perfectly fine in Internet Explorer and both of them return results...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.