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?

Re: Send cookie with WebRequest by arne

arne
Thu May 08 18:21:22 CDT 2008

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

RE: Send cookie with WebRequest by stcheng

stcheng
Thu May 08 23:10:08 CDT 2008

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:
msdnmg@microsoft.com.

==================================================
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.


--------------------
>From: "Dave" <DWeb@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?
>
>
>


RE: Send cookie with WebRequest by stcheng

stcheng
Tue May 13 05:13:49 CDT 2008

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:
msdnmg@microsoft.com.

==================================================
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.

--------------------
>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/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:
>msdnmg@microsoft.com.
>
>==================================================
>Get notification to my posts through email? Please refer to
>http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
>==================================================
>This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>--------------------
>>From: "Dave" <DWeb@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?
>>
>>
>>
>
>