change proxy with webbrowser control

astradamasta

Registered Member
Joined
Nov 24, 2008
Messages
56
Reaction score
8
i have tried for 3 weeks now, cant find anything on google. i am trying to log in to accounts with the webbroswer control but with different proxies...logging in isnt a problem, just changing the proxy is what i need help with....any help would be greatly appreciated, thanks in advance
 
Just did a search for "vb.net webbrowser proxy" and got a whole page of results that explain exactly how to do it. Looks like your google-fu needs some work.

Code:
' The structure we use for the information
' to be interpreted correctly by API.
Public Structure Struct_INTERNET_PROXY_INFO
    Public dwAccessType As Integer
    Public proxy As IntPtr
    Public proxyBypass As IntPtr
End Structure

' The Windows API function that allows us to manipulate
' IE settings programmatically.
Private Declare Auto Function InternetSetOption Lib "wininet.dll" _
(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, _
 ByVal lpdwBufferLength As Integer) As Boolean

' The function we will be using to set the proxy settings.
Private Sub RefreshIESettings(ByVal strProxy As String)
    Const INTERNET_OPTION_PROXY As Integer = 38
    Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
    Dim struct_IPI As Struct_INTERNET_PROXY_INFO

    ' Filling in structure
    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
    struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
    struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")

    ' Allocating memory
    Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))

    ' Converting structure to IntPtr
    System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
    Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub



Code:
RefreshIESettings("127.0.0.1:8080")
 
Thanks very much, but how can i turn off the proxy settings? "localhost" or "127.0.0.1" doesn't work..
Sorry, but i am new at vb. ;)
 
If you use Firefox, you can install a free plugin called Foxy Proxy.
Add your proxies in, then choose the one you wish to use:)
Works well for me!
 
Sorry, but i want to use visual basic net for my own tool. ;)
 
don't use the web browser control. use either HTTPWebRequest, or learn the sockets namespace.

it will pay off many times over in the long term.

here are some links to get you started. spend 3 weeks learning this instead of trying to put a proxy in a web browser and it will be tim much better spent:

Code:
http://www.vbdotnetheaven.com/UploadFile/mahesh/DownloadWebPage04252005073432AM/DownloadWebPage.aspx

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

http://www.worldofasp.net/tut/WebRequest/Working_with_HttpWebRequest_and_HttpWebResponse_in_ASPNET_114.aspx
 
I like webbrowser but with the right possessing power HTTPWebRequest is nice!
 
Agreed. The webbrowser controler is Fed up. I think the Microsoft guys got drunk and made that API.
 
any idea how will i do this if proxy is password proteced?
 
any idea how will i do this if proxy is password proteced?

You set it the same way, but be prepared to enter the username and password in a prompt after your first page load.

Thanks very much, but how can i turn off the proxy settings? "localhost" or "127.0.0.1" doesn't work..
Sorry, but i am new at vb. ;)

Set it to "" or better, string.Empty.
 
Back
Top