using WebRequest with cookie

  • Thread starter Thread starter Sriram Krishnan
  • Start date Start date
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)
 
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.
 
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)
 
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....
 
This appears to be exactly what I'm looking for. Was a code example ever
published for this?
 
Back
Top