Here is the code I have.
Code:
Public Class Form1
<DllImport("User32.dll")> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
End Function
#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
Dim credentialstringvalue As String = (proxyusername & ":" & proxypassword)
Dim credentialbytearray = ASCIIEncoding.ASCII.GetBytes(credentialstringvalue)
Dim credentialbase64string = Convert.ToBase64String(credentialbytearray)
Dim nullObject As Object = 0
Dim nullObjectString As Object = ""
Dim authObject As Object = String.Format("Proxy-Authorization: Basic {0}{1}", credentialbase64string, Environment.NewLine)
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 works perfectly but im using a private proxy, so when my webbrowser naviagtes to a website the Windows security box pops up asking for username password.>>>
How can I automatically input the proxy username(proxyusername) and proxypassword(proxypassword)
I tried doing the following
Dim mycreds As New CredentialCache
Dim proxyauth As New NetworkCredential("user", "pass")
CredentialCache.DefaultNetworkCredentials.UserName = "user"
CredentialCache.DefaultNetworkCredentials.Password = "pass"
CredentialCache.DefaultNetworkCredentials.Domain = "proxyip"
UseProxy("proxy,port")
WebBrowser1.Navigate("http://www.whatismyip.com")