Proxy property of the HttpWebRequest

I've had problems getting through the http proxy where I work at the moment, but I got excellent help from Luke Hutteman, the author of the RSS Aggregator SharpReader. It all works fine now:

...

Dim webReq As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)

Dim newProxy As WebProxy = New WebProxy(host,port)

If username.Length = 0 Then

   newProxy.Credentials = CredentialCache.DefaultCredentials

Else

   Dim cred As New NetworkCredential(username, password)

   Dim credCache As New CredentialCache

   credCache.Add(newProxy.Address, "Basic", cred)

   credCache.Add(newProxy.Address, "Digest", cred)

   newProxy.Credentials = credCache

End If

newProxy.BypassProxyOnLocal = True

webReq.Proxy = newProxy

'some proxys need this too

webReq.Credentials = newProxy.Credentials

Dim objResponse As WebResponse = webReq.GetResponse

...

Something like that :)

No Comments