1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

change proxy with webbrowser control

Discussion in 'Visual Basic .NET' started by astradamasta, Mar 28, 2009.

  1. astradamasta

    astradamasta Registered Member

    Joined:
    Nov 24, 2008
    Messages:
    56
    Likes Received:
    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
     
  2. doseph

    doseph Registered Member

    Joined:
    Feb 23, 2008
    Messages:
    86
    Likes Received:
    24
    Home Page:
    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 Thanks x 3
  3. Kuranyi

    Kuranyi Junior Member

    Joined:
    Dec 21, 2009
    Messages:
    104
    Likes Received:
    51
    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. ;)
     
  4. dan115

    dan115 Newbie

    Joined:
    Apr 28, 2009
    Messages:
    28
    Likes Received:
    68
    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!
     
  5. Kuranyi

    Kuranyi Junior Member

    Joined:
    Dec 21, 2009
    Messages:
    104
    Likes Received:
    51
    Sorry, but i want to use visual basic net for my own tool. ;)
     
  6. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    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
    
     
    • Thanks Thanks x 2
  7. Skills

    Skills Newbie

    Joined:
    Aug 17, 2010
    Messages:
    46
    Likes Received:
    4
    Location:
    Carolina
    I like webbrowser but with the right possessing power HTTPWebRequest is nice!
     
  8. prometheussoft

    prometheussoft Newbie

    Joined:
    Jun 29, 2010
    Messages:
    41
    Likes Received:
    41
    Occupation:
    DBA
    Location:
    Kailua, HI
    Home Page:
    Agreed. The webbrowser controler is Fed up. I think the Microsoft guys got drunk and made that API.
     
  9. prometheussoft

    prometheussoft Newbie

    Joined:
    Jun 29, 2010
    Messages:
    41
    Likes Received:
    41
    Occupation:
    DBA
    Location:
    Kailua, HI
    Home Page:
    Any one ever noticed that the document compelted part fires early, alot.
     
  10. july23

    july23 Jr. VIP Jr. VIP Premium Member

    Joined:
    Nov 27, 2008
    Messages:
    933
    Likes Received:
    426
    Location:
    Lost
    any idea how will i do this if proxy is password proteced?
     
  11. sweepypanda

    sweepypanda Newbie

    Joined:
    Jul 27, 2010
    Messages:
    20
    Likes Received:
    4
    You set it the same way, but be prepared to enter the username and password in a prompt after your first page load.

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