Connect Through Priavte Proxy Using Webclient

TeachMe

Member
Joined
Jun 27, 2012
Messages
16
Programming Experience
Beginner
Hi friends,

So I was trying to connect through a couple private proxies that I've ordered using the Webclient class.
Here's the code that I have thus far, but I don't know the exact lines of code for connecting through using credentials:

VB.NET:
Try
            Dim client As New System.Net.WebClient()
            Dim wp As New System.Net.WebProxy(TextBox1.Text)
            client.Proxy = wp
            Dim str As String = client.DownloadString("https://www.MyLovelySite.com")
            TextBox2.Text = str
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
Would appreciate the help connecting through my private proxies with the credential settings. Thanks again.
 
Where on those pages that you posted here shows how to use the username of the proxy & the password while connecting through the Webclient? I didn't see one example there
that is even similar to the code that I've posted here. Can you elaborate on what you meant? Why did you reference me over to the webclient with private proxies? I don't get it.


 
Hello, TeachMe and JohnH.

I have the same problem.
Did you solve it?

My code is:

Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://Mypage.com.br")
Dim proxyObject As New WebProxy("Server", 3128)
proxyObject.Credentials = New NetworkCredential("User", "password", "domain")
request.Proxy = proxyObject
Dim response As System.Net.HttpWebResponse = request.GetResponse()


If i paste the desired link in the Internet Explorer address box the page is displayed correctly, that's proves the proxy is running and ok.
Only does not work for https sites under my application, but http sites in the same application opens great.

The exception that operation causes is "(407) Proxy Authentication Required".

Some advices in this trouble topic? LOL

Regards
 
Last edited:
If i paste the desired link in the Internet Explorer address box the page is displayed correctly, that's proves the proxy is running and ok.
That means you have a system default proxy and you don't have to set Proxy property of request, it will use the default one.
help said:
If no proxy is specified in a config file and the Proxy property is unspecified, the HttpWebRequest class uses the proxy settings inherited from Internet Explorer on the local computer
 
Thanks for reply, JohnH.
Now i tried other sites https and it works. The difference between them is a valid security certificate on sites that works.
If the certificate is invalidy, i have to choose to continues when in internet explorer. I think that it is the major problem. My application does not have interaction with the site.
Do you know if i could bypass that question to application go ahead?

Regards
 
The problem was solved with the code below:

        'ByPass SSL Certificate Validation Checking
        System.Net.ServicePointManager.ServerCertificateValidationCallback = _
        Function(se As Object, _
         cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
          chain As System.Security.Cryptography.X509Certificates.X509Chain, _
          sslerror As System.Net.Security.SslPolicyErrors) True

'Code to call website



        'Restore SSL Certificate Validation Checking
        System.Net.ServicePointManager.ServerCertificateValidationCallback = Nothing




Everything look like to works now.

Thank's, friends.
 
Back
Top