HTTP Via A Proxy

v7web

Registered Member
Joined
Jul 15, 2010
Messages
64
Reaction score
4
Hi,
Can anyone give me some example code or links to help me with http post via a proxy.
I have mastered the webbrowser control in vb.net and am now moving on to httpwebrequest.
Many thanks.
 
HTML:
    Dim request As HttpWebRequest = HttpWebRequest.Create("http://www.google.com")
       request.Proxy = New Net.WebProxy(ip:port)
       request.Timeout = 5000 'set timeout
       request.KeepAlive = False


       Dim response As HttpWebResponse = request.GetResponse()
       Dim sr As StreamReader = New StreamReader(response.GetResponseStream())
       Dim pageSourceCode As String = sr.ReadToEnd()
 
Many thanks m3ownz
 
I use the following one, works fine for me.

Code:
request.Proxy = New WebProxy("218.100.22.60:80")
 
thanks m3ownz, I was also looking for the same thing. I couldn't change the proxy for httpwebrequest before now it works!
 
If it is for an app that will be used by other people, look into supporting private proxies. You will need to give them the option to say "my proxies require username/password" by having a checkbox. They check the box, and it unlocks the Proxy Username and Proxy Password text boxes.

In your webrequest code, add a check to get the checkstate of the checkbox. If it is checked, then pass the credentials in the WebRequest.
 
If it is for an app that will be used by other people, look into supporting private proxies. You will need to give them the option to say "my proxies require username/password" by having a checkbox. They check the box, and it unlocks the Proxy Username and Proxy Password text boxes.

In your webrequest code, add a check to get the checkstate of the checkbox. If it is checked, then pass the credentials in the WebRequest.


And to do that you extend out the previous proxy example like this.

Code:
Dim IP as string = "127.0.0.1"
Dim PORT as string = "8080"
Dim USERNAME as string = "TestUser"
Dim PASSWORD as string = "TestPass"

Dim proxy As New WebProxy(IP & ":" & PORT, True)
proxy.Credentials = New NetworkCredential(USERNAME, PASSWORD)
request.Proxy = proxy
 
Back
Top