April 2nd, 2009, 12:26 AM
How to use Proxies?
Proxies are HTTP and socks. How can I use them to surf internet?
I know "iwebproxy " of .net but do not understand how to use them for this perpose.
Any guidance will be appriciated.
Last edited by memo421; April 2nd, 2009 at 12:28 AM.
April 2nd, 2009, 09:09 AM
Re: How to use Proxies?
Create a new form. Put a webbrowser object on it then use this code. Change the "SetupProxy" arguments as you need:
Just typed this up real quick so it needs testing but it should give you a good start. All web requests in your application should follow what is set here so you can have a form that lets them select "direct connect" (no proxy), use default system proxy, or enter their own.
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If SetupProxy(False) Then
Public Function SetupProxy(ByVal UseProxy As Boolean, Optional ByVal ProxyName As String = "", Optional ByVal ProxyPort As Integer = 0, Optional ByVal UserName As String = "", Optional ByVal UserPassword As String = "", Optional ByVal UserDomain As String = "") As Boolean
' Create our proxy settings
If UseProxy = False Then
Net.WebRequest.DefaultWebProxy = New Net.WebProxy
If (ProxyName = "") Or (ProxyPort = 0) Then
If UseProxy = True Then
MsgBox("Either the proxy name or port number was left blank but the option to use a proxy server is checked. Please review your settings before updating!")
SetupProxy = False
Dim ProxyObject As New System.Net.WebProxy(ProxyName & ":" & ProxyPort, True)
Dim cred As Net.NetworkCredential = New Net.NetworkCredential(UserName, UserPassword, UserDomain)
ProxyObject.Credentials = cred
Net.WebRequest.DefaultWebProxy = ProxyObject
SetupProxy = True
For use system proxy you can pull whats in the registry with something like this:
Which will get you ProxyName:PortNumber which you will split apart (based on the and use as you need.
Private Function ImportSystemSettings() As String
' Get the IE proxy settings
Dim myProxy As String = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "").ToString
If myProxy = "" Then
MsgBox("I could not find any proxy server information in the registry. If a proxy server is required please manually enter the information.", MsgBoxStyle.OkOnly, "No Proxy Info Found")
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!