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:
  1. Option Strict On
  2.  
  3. Imports System.Net
  4. Imports System.IO
  5.  
  6.  
  7. Private Sub Button2_Click(ByVal sender As System.Object, _
  8.                               ByVal e As System.EventArgs) Handles Button2.Click
  9.  
  10.         Dim uri As New Uri("http://www.geocities.com/trisuglow/readme.txt")
  11.  
  12.         Dim wreq As HttpWebRequest
  13.         wreq = CType(WebRequest.Create(uri), HttpWebRequest)
  14.  
  15.         Dim cr As New System.Net.NetworkCredential("username", "password")
  16.         wreq.Credentials = cr
  17.         wreq.PreAuthenticate = True
  18.         wreq.Proxy.Credentials = cr
  19.  
  20.         Dim wrsp As WebResponse
  21.         Try
  22.             wrsp = wreq.GetResponse()
  23.  
  24.             Dim s As Stream = wrsp.GetResponseStream
  25.  
  26.             Dim br As New BinaryReader(s)
  27.             MsgBox(s.Length, , "File Length")
  28.  
  29.         Catch wex As WebException
  30.             Debug.WriteLine("Message: " & wex.Message)
  31.             Debug.WriteLine("Response: " & wex.Response.GetResponseStream.ToString)
  32.             Debug.WriteLine("ResponseURI: " & wex.Response.ResponseUri.ToString)
  33.             Debug.WriteLine("Source: " & wex.Source.ToString)
  34.             Debug.WriteLine("Status: " & wex.Status.ToString)
  35.         End Try
  36.  
  37.     End Sub