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: