473,587 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send cookie with WebRequest

string m_request = some_web_page;

HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(m_request );

HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

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 8162
Dave wrote:
string m_request = some_web_page;

HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(m_request );

HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

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.Cook ieContainer
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****@microsof t.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;

HttpWebReque st request = (HttpWebRequest )WebRequest.Cre ate(m_request );

HttpWebRespons e response = (HttpWebRespons e)request.GetRe sponse();

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****@microsof t.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
CookieContaine r instance and attach it to the WebRequest.Cook ieContainer
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
CookieContaine r:
#Establishin g 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****@microso ft.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;

HttpWebReques t request = (HttpWebRequest )WebRequest.Cre ate(m_request );

HttpWebRespon se response = (HttpWebRespons e)request.GetRe sponse();

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1187
by: | last post by:
Hello, I can use WebRequest when accessing web sites that don't require a cookie. However, when I want to use it to get an html page from a web site that I have a current cookie for, I an unable to get things to work. I don't know how to point to the existing cookie. Any help would be greatly appreciated.
17
7225
by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values and in the debugger I can see the value I want in the property
4
2282
by: octavio.filipe | last post by:
Hi, I'm trying to use the following code: HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest; webRequest.CookieContainer = new CookieContainer(); HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
0
1556
by: vMike | last post by:
I don't know if I can explain this here, but I will try. I am using WebRequest/WebResponse to get product information from another website then put the selections in a shopping cart of the remote site. (So that I can tract what is purchased) I all works fine until checkout time because at check out time I have to use a Response.Redirect and I...
5
2936
by: Ya Ya | last post by:
I am trying to download a web page using WebRequest. The problem is that this page uses cookies. In IE, I can view this page correctly (since I have the cookie) but when downloading using WebRequest I don't get the page I want. How can I add cookie information to my WebRequest ? How do I know which cookie information the page need ? A code...
1
4694
by: mfreeman | last post by:
I have a VB.NET 2005 Windows application that worked fine when I ran it a month ago, and now it is throwing an exception ("The remote server returned an error: (500) Internal Server Error.") and I don't know why. The application screen scrapes a web page. If I paste the URL in my browser's address bar and the expected page comes up just...
1
1422
by: tohnsm | last post by:
Hi. I have been trying to create a cookie container. But the cookie I have stored is not correct. Below is the code: request = CType(WebRequest.Create("....."), httpWebRequest) request.CookieContainer = New CookieContainer() myCookie = request.CookieContainer ' store the cookie as global variavble
1
155
by: Dave | last post by:
I'm sending data to a website with a WebRequest, string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
1
18623
by: dschu012 | last post by:
I am logging into a site using a WebBrowser. Once I log in I want to save an Image from within it without having to make the WebBrowser navigate to the URL where the Image is stored. Currently I am doing this HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri); request.Headers.Add(HttpRequestHeader.Cookie,...
0
7843
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...
0
8205
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. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5712
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...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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...
1
2347
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
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.