1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
Private responseScrape As HttpWebResponse
Private requestScrape As HttpWebRequest
' This function uses .NET classes that derive from System.Net.WebRequest to
' retrieve an HTTP response Stream that becomes the RegEx parsing source or the
' image to be displayed when called by frmImageViewer.Show().
Function GetHttpStream(ByVal url As String) As Stream
' Create the request using the WebRequestFactory.
requestScrape = CType(WebRequest.Create(url), HttpWebRequest)
With requestScrape
.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)"
.Method = "GET"
.Timeout = 10000
End With
Try
' Return the response stream.
responseScrape = CType(requestScrape.GetResponse(), HttpWebResponse)
Return responseScrape.GetResponseStream()
Catch exp As Exception
' As the error is most likely caused by a mistyped Url or not having
' a connection to the Internet, create a custom error message that
' is forwarded back to the calling function.
Throw New Exception("There was an error retrieving the Web page " & _
"you requested. Please check the Url and your connection to " & _
"the Internet, and try again.")
End Try
End Function |
Partager