0

So basically i've got this code made from bits and pieces, and i use it as an event listener when WebBrowser1.navigating is triggered so it will use the proxy on every navigation, no exception.

The only problem is that i don't know how to modify the code to use a private proxy based on id:pass

#Region "Using Proxy"
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function

Public Structure Struct_INTERNET_PROXY_INFO
    Public dwAccessType As Integer
    Public proxy As IntPtr
    Public proxyBypass As IntPtr
End Structure

Private Sub UseProxy(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

    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

    Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

    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
#End Region

This is the code snippet i'm using wherever i need it:

Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
    UseProxy(TextBox3.Text & ":" & TextBox4.Text)
End Sub

I'm sure that the solution to this is abysmally simple, just that it's avoiding my mad VB skills!

  • Duplicate http://stackoverflow.com/questions/23767475/how-can-i-set-a-proxy-with-authentication-username-password-on-the-webbrowse – Sam Makin Feb 23 '15 at 13:20
  • and again http://www.blackhatworld.com/blackhat-seo/visual-basic-net/385225-vbulletin-help-needed-proxies.html – Sam Makin Feb 23 '15 at 13:21
  • best answer I have found http://stackoverflow.com/a/300738/2319909 – Sam Makin Feb 23 '15 at 13:28
  • more info http://sticklebackplastic.com/post/2007/01/26/Poxy-proxies.aspx – Sam Makin Feb 23 '15 at 13:28
  • Aw damn, i'm so sorry for my ignorance, it won't happen again! i'll proceed to the links ASAP. Thanks for posting them, and sorry again :( – immortall69 Feb 23 '15 at 13:40
  • No problem - took me a while to find the actual code to solve the problem (see answer below!) Seems like lots of peopole have had the same issue before. Google is your friend! – Sam Makin Feb 23 '15 at 13:41

1 Answers1

0

This KB article explains how to implement authentication with wininet library

How To Handle Proxy Authorization with WinInet

Sam Makin
  • 1,526
  • 8
  • 23