Proxy Authentication Required (407)
I'm using the following code to access a file on the Internet. I'm running it on my PC at work which connects to the Internet through a proxy.
When the code gets to the GetResponse line a Proxy Authentication Required (407) error occurs.
I know this problem has been raised a few times before, but there don't seem to be any answeres out there. Can anybody help?
"username" and "password" in the code are what I use to log onto the network with.
VB Code:
Option Strict On
Imports System.Net
Imports System.IO
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim uri As New Uri("http://www.geocities.com/trisuglow/readme.txt")
Dim wreq As HttpWebRequest
wreq = CType(WebRequest.Create(uri), HttpWebRequest)
Dim cr As New System.Net.NetworkCredential("username", "password")
wreq.Credentials = cr
wreq.PreAuthenticate = True
wreq.Proxy.Credentials = cr
Dim wrsp As WebResponse
Try
wrsp = wreq.GetResponse()
Dim s As Stream = wrsp.GetResponseStream
Dim br As New BinaryReader(s)
MsgBox(s.Length, , "File Length")
Catch wex As WebException
Debug.WriteLine("Message: " & wex.Message)
Debug.WriteLine("Response: " & wex.Response.GetResponseStream.ToString)
Debug.WriteLine("ResponseURI: " & wex.Response.ResponseUri.ToString)
Debug.WriteLine("Source: " & wex.Source.ToString)
Debug.WriteLine("Status: " & wex.Status.ToString)
End Try
End Sub