Error when trying to read HTML page

Pyth007

Member
Joined
Nov 17, 2008
Messages
18
Programming Experience
5-10
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:

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.
 
try this:

VB.NET:
        Dim webrequest As HttpWebRequest = CType(Net.WebRequest.Create("http://www.google.com"), HttpWebRequest)
        Dim objResponse As HttpWebResponse = CType(webrequest.GetResponse(), HttpWebResponse)
        Using sr As New StreamReader(objResponse.GetResponseStream())
            Dim result As String = sr.ReadToEnd
            sr.Close()
            Console.Write(result)
        End Using
 
I'm still getting the same error... I looked at my firewall and it didn't say that it blocked it, but could there be an issue with security somewhere? Or with the way our network is setup?
 
Argh! I feel like a moron right now... I had been working on a different project to disable browsing on computers out on the manufacturing floor, and had set my proxy to 127.0.0.1 in Internet Options. Although this blocks IE, it doesn't block Firefox, the latter being my main browser. Apparently this also blocks my program too (it'd make sense since .net is also an MS product). To think banging my head for so many months just to find out it was all a stupid mistake! :eek:
 
Back
Top