473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

using WebRequest with cookie

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 example will be great.

Here is my code:
Dim szDate As String = ""
Dim NetDataRequest As System.Net.WebRequest =
System.Net.WebRequest.Create(szUrl)
Dim NetDataResponse As System.Net.WebResponse = NetDataRequest.GetResponse()
Dim StreamRead As System.IO.StreamReader
StreamRead = New System.IO.StreamReader(NetDataResponse.GetResponse Stream(),
System.Text.Encoding.ASCII)
szDate = StreamRead.ReadToEnd()
NetDataResponse.Close()
StreamRead.Close()
Return szDate

Thanks for your time

ra***@hotmail.com
Nov 21 '05 #1
5 2912
"Ya Ya" <ra***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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 example will be great.

Here is my code:
Dim szDate As String = ""
Dim NetDataRequest As System.Net.WebRequest =
System.Net.WebRequest.Create(szUrl)
Dim NetDataResponse As System.Net.WebResponse = NetDataRequest.GetResponse() Dim StreamRead As System.IO.StreamReader
StreamRead = New System.IO.StreamReader(NetDataResponse.GetResponse Stream(), System.Text.Encoding.ASCII)
szDate = StreamRead.ReadToEnd()
NetDataResponse.Close()
StreamRead.Close()
Return szDate

Thanks for your time

ra***@hotmail.com


Your cookie collection will be populated initially after you log in (or
select your settings). You must then be sure to hand that cookie (or cookie
collection) back with each request.
Nov 21 '05 #2
You have to use a CookieContainer

--
Sriram Krishnan

http://www.dotnetjunkies.com/weblog/sriram
"Chris Hornberger" <chris@no_spam.chornbe.com> wrote in message
news:M5********************@comcast.com...
"Ya Ya" <ra***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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 example will be great.

Here is my code:
Dim szDate As String = ""
Dim NetDataRequest As System.Net.WebRequest =
System.Net.WebRequest.Create(szUrl)
Dim NetDataResponse As System.Net.WebResponse =

NetDataRequest.GetResponse()
Dim StreamRead As System.IO.StreamReader
StreamRead = New

System.IO.StreamReader(NetDataResponse.GetResponse Stream(),
System.Text.Encoding.ASCII)
szDate = StreamRead.ReadToEnd()
NetDataResponse.Close()
StreamRead.Close()
Return szDate

Thanks for your time

ra***@hotmail.com


Your cookie collection will be populated initially after you log in (or
select your settings). You must then be sure to hand that cookie (or
cookie
collection) back with each request.

Nov 21 '05 #3
Do you mean I need to do webRequest to the login page first (posting the
user/pass as parameters) , and then pass the CookieContainer to another
webRequest for the page I need ?

Thanks
ra***@hotmail.com

"Chris Hornberger" <chris@no_spam.chornbe.com> wrote in message
news:M5********************@comcast.com...
"Ya Ya" <ra***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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 example will be great.

Here is my code:
Dim szDate As String = ""
Dim NetDataRequest As System.Net.WebRequest =
System.Net.WebRequest.Create(szUrl)
Dim NetDataResponse As System.Net.WebResponse =

NetDataRequest.GetResponse()
Dim StreamRead As System.IO.StreamReader
StreamRead = New

System.IO.StreamReader(NetDataResponse.GetResponse Stream(),
System.Text.Encoding.ASCII)
szDate = StreamRead.ReadToEnd()
NetDataResponse.Close()
StreamRead.Close()
Return szDate

Thanks for your time

ra***@hotmail.com


Your cookie collection will be populated initially after you log in (or
select your settings). You must then be sure to hand that cookie (or
cookie
collection) back with each request.

Nov 21 '05 #4
"Ya Ya" <ra***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Do you mean I need to do webRequest to the login page first (posting the
user/pass as parameters) , and then pass the CookieContainer to another
webRequest for the page I need ?

yessir.

Let me see if I can find a snippet of a production app we're using at the
office for you to see....
Nov 21 '05 #5
This appears to be exactly what I'm looking for. Was a code example ever
published for this?

"Chris Hornberger" wrote:
"Ya Ya" <ra***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Do you mean I need to do webRequest to the login page first (posting the
user/pass as parameters) , and then pass the CookieContainer to another
webRequest for the page I need ?

yessir.

Let me see if I can find a snippet of a production app we're using at the
office for you to see....

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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...
1
by: Peter | last post by:
Hi I am trying to do very simple http client that requires a login, copy cookie snet by a server and does a request with the cookies. WebRequest->CookieContainer/WebResponse->Cookies does not...
1
by: Vasu | last post by:
Hi, I have a requirement to download a file from the web site using a client tool. Iam writing a C# program to download using WebRequest, HttpRequest, WebResponse and so on. The problem...
17
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...
0
by: Tony Archer | last post by:
Here's my problem... When I use this code to hit the site in question I'm redirected to another SSL login page. If processed successfully the page creates a cookie and then redirects you to the...
6
by: matt | last post by:
hello, i am having trouble doing something. when a user triggers a certain event in my app, i need to initiate another web request to one of my other webpages, programmatically. currently, i do...
1
by: WeCi2i | last post by:
Okay, I have a problem that has been stumping me for weeks. I have tried many different solutions and this is pretty much my last resort. I have seen a lot of good answers give here so I figured I...
3
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.