using WebRequest with cookie

Y

Ya Ya

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.GetResponseStream(),
System.Text.Encoding.ASCII)
szDate = StreamRead.ReadToEnd()
NetDataResponse.Close()
StreamRead.Close()
Return szDate

Thanks for your time

(e-mail address removed)
 
C

Chris Hornberger

Ya Ya said:
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.GetResponseStream(),
System.Text.Encoding.ASCII)
szDate = StreamRead.ReadToEnd()
NetDataResponse.Close()
StreamRead.Close()
Return szDate

Thanks for your time

(e-mail address removed)

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

Ya Ya

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
(e-mail address removed)
 
C

Chris Hornberger

Ya Ya said:
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....
 
G

Guest

This appears to be exactly what I'm looking for. Was a code example ever
published for this?
 

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