S
scott rosa
I am having an issue with using the httpwebrequest to
perform a screenscrape. The site I am retrieving data
from has forms based authentication. When I pass the
correct credentials it authenticates properly, but then I
get an error saying too many redirections attempted. Here
is the code I am using:
--------------------------------------------------------
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim x As String
x = readHtmlPage("http://awebsite.com")
End Sub
Function readHtmlPage(ByVal url As String) As String
Dim objResponse As WebResponse
Dim result As String
Dim myCred As New NetworkCredential("uname", "pw")
Dim myCache As New CredentialCache
myCache.Add(New Uri(url), "Basic", myCred)
Dim wr As HttpWebRequest = HttpWebRequest.Create
(url)
wr.Credentials = myCache
wr.AllowAutoRedirect = True
wr.MaximumAutomaticRedirections = 5
Dim myWebResponse As HttpWebResponse =
wr.GetResponse()
Dim sr As New StreamReader(myWebResponse.GetResponseStream
())
result = sr.ReadToEnd()
'clean up StreamReader
sr.Close()
Return result
End Function
----------------------------------------------
Can anyone assist?
Thanks,
Scott
perform a screenscrape. The site I am retrieving data
from has forms based authentication. When I pass the
correct credentials it authenticates properly, but then I
get an error saying too many redirections attempted. Here
is the code I am using:
--------------------------------------------------------
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim x As String
x = readHtmlPage("http://awebsite.com")
End Sub
Function readHtmlPage(ByVal url As String) As String
Dim objResponse As WebResponse
Dim result As String
Dim myCred As New NetworkCredential("uname", "pw")
Dim myCache As New CredentialCache
myCache.Add(New Uri(url), "Basic", myCred)
Dim wr As HttpWebRequest = HttpWebRequest.Create
(url)
wr.Credentials = myCache
wr.AllowAutoRedirect = True
wr.MaximumAutomaticRedirections = 5
Dim myWebResponse As HttpWebResponse =
wr.GetResponse()
Dim sr As New StreamReader(myWebResponse.GetResponseStream
())
result = sr.ReadToEnd()
'clean up StreamReader
sr.Close()
Return result
End Function
----------------------------------------------
Can anyone assist?
Thanks,
Scott