I've been searching the internet and this site and haven't been able to find an answer to what I believe should be easy to do.
I'm using Visual Basic 2008 Express and I'm trying to retrieve a web page. I'm using the following code (that I found on the web):
Public Sub New(ByVal URL As String, _
Optional ByVal TimeoutSeconds As Integer = 10)
' Retrieves the HTML from the specified URL,
' using a default timeout of 10 seconds
Dim objRequest As Net.WebRequest
Dim objResponse As Net.WebResponse
Dim objStreamReceive As System.IO.Stream
Dim objEncoding As System.Text.Encoding
Dim objStreamRead As System.IO.StreamReader
Try
' Setup our Web request
objRequest = Net.WebRequest.Create(URL)
objRequest.Timeout = TimeoutSeconds * 1000
objRequest.UseDefaultCredentials = True
' Retrieve data from request
objResponse = objRequest.GetResponse
objStreamReceive = objResponse.GetResponseStream
objEncoding = System.Text.Encoding.GetEncoding( _
"utf-8")
objStreamRead = New System.IO.StreamReader( _
objStreamReceive, objEncoding)
' Set function return value
theHTML = objStreamRead.ReadToEnd()
' Check if available, then close response
If Not objResponse Is Nothing Then
objResponse.Close()
End If
valid = True
Catch
' Error occured grabbing data, simply return nothing
theHTML = ""
valid = False
End Try
End Sub
This works if the web page doesn't require login, but I'm trying to use it with a site that requires login. I assume the site saves the login information in a cookie. If I type in the URL in IE, the site brings up the right page, but if I use the exact same URL string in Visual Basic, the site returns a login page.
What is IE doing behind the scenes that I need to add to my Visual Basic code?
Thanks for all your help.
Randy