471,344 Members | 1,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Send cookie with WebRequest

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?
Jun 27 '08 #1
3 7959
Dave wrote:
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
Jun 27 '08 #2
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/archiv...24/219714.aspx

#Help needed with cookies and WebRequest
http://forums.microsoft.com/MSDN/Sho...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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Dave" <DW**@newsgroup.nospam>
Subject: Send cookie with WebRequest
Date: Thu, 8 May 2008 19:04:08 -0400
Lines: 12

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?
Jun 27 '08 #3
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:
ms****@microsoft.com.

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

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

--------------------
>Organization: Microsoft
Date: Fri, 09 May 2008 04:10:08 GMT
Subject: RE: Send cookie with WebRequest
>
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/archiv...24/219714.aspx

#Help needed with cookies and WebRequest
http://forums.microsoft.com/MSDN/Sho...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:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ault.aspx#noti
f
>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/subscripti...t/default.aspx.
================================================= =
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>>From: "Dave" <DW**@newsgroup.nospam>
Subject: Send cookie with WebRequest
Date: Thu, 8 May 2008 19:04:08 -0400
Lines: 12

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?

Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by James Johnson | last post: by
4 posts views Thread by octavio.filipe | last post: by
reply views Thread by vMike | last post: by
5 posts views Thread by Ya Ya | last post: by
1 post views Thread by tohnsm | last post: by
1 post views Thread by Dave | last post: by
reply views Thread by Ronak mishra | last post: by

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.