Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27206

VS 2012 [RESOLVED] Using proxy with WebClient

$
0
0
Hi, I am looking into using a proxy with the WebClient.

The code I am trying is:
VB.NET Code:
  1. Using WClient As New WebClient
  2.     WClient.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)")
  3.  
  4.     Dim WProxy As New WebProxy("<IP>:<Port>")
  5.     WClient.Proxy = WProxy
  6.  
  7.     'I am using this website to test the current IP
  8.     MessageBox.Show(Encoding.UTF8.GetString(WClient.DownloadData("http://checkip.dyndns.org/")))
  9. End Using
When I retrieve my IP from dyndns using the MessageBox above it is showing my own IP. Some of the proxy IP's I have tested use https so I also tried the code below:
VB.NET Code:
  1. Private Shared Function BypassCertificate(ByVal sender As Object, ByVal cert As X509Certificate, ByVal chain As X509Chain, ByVal [error] As System.Net.Security.SslPolicyErrors) As Boolean
  2.     Return True
  3. End Function
  4.  
  5. Private Sub TestProxy()
  6.     ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf BypassCertificate)
  7.     Using WClient As New WebClient
  8.         WClient.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)")
  9.  
  10.         Dim WProxy As New WebProxy("<IP>:<Port>")
  11.         WClient.Proxy = WProxy
  12.  
  13.         MessageBox.Show(Encoding.UTF8.GetString(WClient.DownloadData("http://checkip.dyndns.org/")))
  14.     End Using
  15. End Sub
However I still get the same result.

Am I doing this wrong? Or could it be that the proxy is working but that the IP lookup websites look beyond the proxy back to the source? If so, how would I test that it is working?

Thanks
Jay

Viewing all articles
Browse latest Browse all 27206

Trending Articles