Multiple Webbrowser controls running with different proxies
I'm trying to run a specific test on my server using a program that can run multiple requests (using Webbrowser control) at the same time but with different proxy settings. What I am using now is working but only for one webbrowser control, im seeking advice for how to run multiple side-by-side.
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function InternetSe开发者_JAVA百科tOption(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 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 = Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
' Allocating memory
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
' Converting structure to IntPtr
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
Private Function loadpage()
sInputLine = srFileReader.ReadLine()
Debug.WriteLine("Starting Proxy " & sInputLine)
RefreshIESettings(sInputLine)
Timer1.Enabled = True
Timer1.Interval = My.Settings.timeout * 1000
'set label
Label3.Text = "Attempting: " & sInputLine
Label3.ForeColor = Color.Black
Label3.Visible = True
WebBrowser1.Navigate("http://www.MYSERVER.com")
Return True
End Function
The loadpage() is being looped from a timer within DocumentCompleted Event.
Please help, I have searched -days- for a solution.
Can't help you with the webbrowser control itself, but you could manually retrieve the remote content using HttpWebRequest which has a Proxy property. http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.proxy.aspx
精彩评论