WebClient "unable to connect to remote server"

paulanthony22

Member
Joined
Jul 3, 2007
Messages
7
Programming Experience
1-3
Folks I can get neither of these subs to work behind a firewall..Anyone any ideas. Do I need to Auth against the proxy server or should it not pick up the settings on the client machines.

VB.NET:
Public Sub DownloadXMLWeb()
        Dim request As HttpWebRequest = CType(WebRequest.Create("url here"), HttpWebRequest)
        ' Set credentials to use for this request.
        request.Credentials = CredentialCache.DefaultCredentials
        request.Proxy = WebRequest.DefaultWebProxy

        Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
        ' Get the stream associated with the response.
        Dim receiveStream As Stream = response.GetResponseStream()


        ' Pipes the stream to a higher level stream reader with the required encoding format. 
        Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)
        Dim objStreamWriter As New StreamWriter(Application.StartupPath & "\brochure.xml")
        objStreamWriter.Write(readStream.ReadToEnd())
        objStreamWriter.Close()

        response.Close()
        readStream.Close()
    End Sub

    Public Sub DownloadXML()

        Dim wc As New WebClient
        Dim wp As New WebProxy
        wp.UseDefaultCredentials = True
        Try
            wc.Proxy = wp
            wc.DownloadFile("url here", Application.StartupPath & "\brochure.xml")
        Catch ex As Exception
            MsgBox("Download failed: " & ex.Message)
        End Try
        wc.Dispose()

    End Sub
 
Last edited by a moderator:
I would guess you have to open the firewall for the application if it's blocking outgoing connections. Windows Firewall XP for example only blocks incoming connections, but I know several third-party firewalls also blocks outgoing, there is usually a dialog first time an application tries to get internet access where you can make a rule of it (always allow/deny).
 
This isn't really an option when trying to deploy an application to other corporates. You cant ask them to change their proxy to suit the program, instead I want to enable settings inside the form, which can be used to successfully get through the firewall. Im just using a web request (standard port 80) which should be open for browsing the web on the machines I intend to deploy on. Any further details appreciated.
 
Back
Top