I am trying to parse a web-page by having my vb.net program grab the HTML from off the internet. I have a simple function that I want to develop; GetHTML(strURL as String) as String. Basically given a URL address, return the page source as a string. I have tried a variety of ways to do this, but each time I keep getting the error "No connection could be made because the target machine actively refused it." This is just a public web-site (I've even tested with "HTTP://www.google.com" as the URL with the same error-result) so I wouldn't think it is a security issue. Here are the functions that I've tried so far:
Actually, the last version of the function gives the error "The system cannot locate the resource specified." at the oHTTP.send() line...
I'm not sure why I am having so much trouble. All functions have come from various tutorials to connect to the web, but nothing seems to be working for me. Let me know if you need more info. to help me with my problem.
VB.NET:
Public Function GetHTML(ByVal strURL As String) As String
Dim objWeb As New System.Net.WebClient()
Return New System.Text.UTF8Encoding().GetString(objWeb.DownloadData(strURL))
End Function
VB.NET:
Public Function GetHTML(ByVal url As String) As String
Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
myWebRequest.Method = "GET"
' Make Request for the Web Page
Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)
Dim myWebSource As New StreamReader(myWebResponse.GetResponseStream())
Dim myPageSource As String = String.Empty
myPageSource = myWebSource.ReadToEnd()
myWebResponse.Close()
Return myPageSource
End Function
VB.NET:
Function GetHTML(ByVal strURL As String) As String
Dim oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.open("GET", strURL, False)
oHTTP.send()
Dim strResult As String = oHTTP.responseText
Return strResult
End Function
Actually, the last version of the function gives the error "The system cannot locate the resource specified." at the oHTTP.send() line...
I'm not sure why I am having so much trouble. All functions have come from various tutorials to connect to the web, but nothing seems to be working for me. Let me know if you need more info. to help me with my problem.