Today I just wrote code to use httpwebrequest get remote web pages, to avoid the error 407. you need to bypass the proxy server or firewall

Imports System

Imports System.Net

Imports System.Text

Imports System.IO

Public Class Test

‘ Specify the URL to receive the request.

Public Shared Sub Main(ByVal args() As String)

Dim request As HttpWebRequest = CType(WebRequest.Create(args(0)), HttpWebRequest)

Dim networkCredential As New NetworkCredential(“username”, “paswword”, “domain”)

‘ Set some reasonable limits on resources used by this request

request.MaximumAutomaticRedirections = 4

request.MaximumResponseHeadersLength = 4

‘ Set credentials to use for this request.

request.Credentials = networkCredential

Dim pry As System.Net.WebProxy = New System.Net.WebProxy(“proxyserver”, 8080)

‘The DefaultCredentials automically get username and password.

pry.Credentials = networkCredential

WebRequest.DefaultWebProxy = pry

Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

Console.WriteLine(“Content length is {0}”, response.ContentLength)

Console.WriteLine(“Content type is {0}”, response.ContentType)

‘ 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)

Console.WriteLine(“Response stream received.”)




End Sub ‘Main

End Class ‘Test