473,597 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5746
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********@hot mail.com> wrote in message
news:eg******** ******@tk2msftn gp13.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*******@hotm ail.nospam.com> wrote in message
news:BFcCd.3219 42$HA.82793@att bi_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********@hot mail.com> wrote in message
news:eg******** ******@tk2msftn gp13.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********@hot mail.com> wrote in message
news:uG******** ******@TK2MSFTN GP10.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*******@hotm ail.nospam.com> wrote in message
news:BFcCd.3219 42$HA.82793@att bi_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********@hot mail.com> wrote in message
news:eg******** ******@tk2msftn gp13.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
1743
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 and cookies are not being sent along with the header and post data. here is the code im using. Can anyone please tell me why this is happening? I do not want to go back to using VB6 and the inet control!!! If you notice in my class below, i...
0
275
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. Can someone please explain the discrepancy? Thanks, Prasanna
3
15849
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(), Encoding.UTF8); string html = sr.ReadToEnd(); </code>
1
4197
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 code the line Console.WriteLine("cookies1 count : " + firstResponse.Count.ToString()); and Console.WriteLine("second Cookie : " + secondResponse.Cookies.Count.ToString());
3
1828
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 not display that and display the actual page, i did get it at some stage, ut that involved a bit of recursion, by callin the method again (from within itself) and that allowed the page to be displayed. But when i have tried to call a POST...
1
1788
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 returns the correct list of cookies (represented as a comma-separated string) in the response. Can someone please explain the discrepancy? Thanks,
16
11036
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 read documents on the CookieCollection property of HttpWebRequest. Currently, I have the functionality in my code to be able to accept cookies, and return them upon a new HttpWebRequest; however, upon further inspection of the returning...
2
3392
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 404. How am I still able to read the cookies even though I get an exception? Here's the code:
2
9676
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 "pretty quickly". The first URL I try takes a while but eventually comes back with the correct results. It took *much longer* than in Internet Explorer. The second URL times out even if I increase the timeout value significantly. Internet explorer...
0
7884
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5844
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2394
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1229
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.