Send cookie with WebRequest

D

Dave

string m_request = some_web_page;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request );

HttpWebResponse response = (HttpWebResponse)request.GetResponse();



Which works fine, but I need to set and send a cookie with the WebRequest.
How do I do that?
 
A

Arne Vajhøj

Dave said:
string m_request = some_web_page;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request );

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Which works fine, but I need to set and send a cookie with the WebRequest.
How do I do that?

HttpWebRequest has a property CookieContainer which is of type
CookieContainer that has an Add method ... !

Arne
 
S

Steven Cheng [MSFT]

Hi Dave,

As for HttpWebRequest component, if you want to maintain cookies between
multiple WebRequest instances(and webrequest calls), you need to create an
CookieContainer instance and attach it to the WebRequest.CookieContainer
property.

Also, if you want the cookies to share between multiple WebRequest
instances, you need to make sure all of those WebRequest instances use the
same cookie container.

here are some web thread that also mentioned some code that use
CookieContainer:


#Establishing cookie based session with WebServices and HttpWebRequest
http://blogs.msdn.com/adarshk/archive/2004/08/24/219714.aspx

#Help needed with cookies and WebRequest
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=99324&SiteID=1

If you have any further questions, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
S

Steven Cheng [MSFT]

Hi Dave,

Have you got progress on this issue or does the suggestion in our previous
reply help you some? If you need any further help on this, welcome to post
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

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