我想知道是否可以为应用程序中的每个不同的webbrowser设置代理(相同的过程)。
我已经搜索了很多代码,通过修改注册表和另一个特定于进程的代理来查找更改代理系统范围的代码。但我希望同一进程内的每个webbrowser都有不同的代理
例如:WebBrowser1代理 - > 95.188.106.78:3128
WebBrowser 2代理 - > 89.218.160.162:9090
WebBrowser 3代理 - > 78.39.68.145:3128等等
或者如果直接使用WebBrowser是不可能的,那么任何人都可以建议我可以使用什么来实现这一点(不是webrequests,我只想通过浏览器来加载所有数据,用户可以与它进行交互,但不同代理)比如使用geckofx或webkit?但我不知道它是否可能存在于其中
答案 0 :(得分:1)
答案 1 :(得分:0)
不幸的是,你不能为每个insnance设置代理。甚至不是每个应用程序 - 它是全球性的。如果您使用.net应用程序,它也会影响IE。
以下是更改代理的完整代码。
使用“B_Get”“B_Set”和“B_Disable”按钮创建“Form1”,然后粘贴此代码。
它应该适合你。我使用这个应用程序作为我构建的自动代理循环仪的概念证明。
根据您的应用程序需求,您可以切换它,然后将其切换回来。请注意,它会影响Internet Explorer。
要验证这是否有效,请检查Internet Explorer。您可能必须打开/关闭IE的选项对话框,但您不需要重新启动浏览器。
这也将动态影响.NET应用程序 - 如果您在运行程序时运行我的程序,您将能够更改程序正在使用的代理程序。
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("wininet.dll")>
Public Shared Function InternetSetOption(hInternet As IntPtr, dwOption As Integer, lpBuffer As IntPtr, dwBufferLength As Integer) As Boolean
End Function
Public Const INTERNET_OPTION_SETTINGS_CHANGED As Integer = 39
Public Const INTERNET_OPTION_REFRESH As Integer = 37
'This function is what is called after editing the registry - this causes internet explorer to update its proxy even if it is already open.
'It also effects the web browser control in any VB.net application that is running.
Public Sub globalProxy_apply()
Dim settingsReturn As Boolean = False
Dim refreshReturn As Boolean = False
settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0)
If Not settingsReturn Then
MessageBox.Show("Error 001: Line ""InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0)"" failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0)
If Not refreshReturn Then
MessageBox.Show("Error 002: Line ""InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0)"" failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Public Function globalProxy_IsProxyEnabled() As Boolean
Try
Dim Regs As RegistryKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", RegistryKeyPermissionCheck.ReadWriteSubTree)
If Regs.GetValue("ProxyEnable") <> Nothing Then
If Regs.GetValue("ProxyEnable").ToString() = "0" Then
Return False
Else
Return True
End If
Else
Return False
End If
Catch ex As Exception
MessageBox.Show("Error 01X: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
Public Function globalProxy_GetProxyServer() As String
Try
Dim Regs As RegistryKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", RegistryKeyPermissionCheck.ReadWriteSubTree)
If Regs.GetValue("ProxyServer") <> Nothing Then
Return Regs.GetValue("ProxyServer").ToString()
Else
Return ""
End If
Catch ex As Exception
MessageBox.Show("Error 02X: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return ""
End Try
End Function
Public Sub globalProxy_DisableProxy()
Dim regkey As RegistryKey
Try
regkey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings")
regkey.SetValue("ProxyEnable", False, RegistryValueKind.DWord)
regkey.Close()
Catch ex As Exception
MessageBox.Show("Error 03X: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
globalProxy_apply()
End Sub
Public Sub globalProxy_SetProxy(ByVal ServerName As String)
Dim regkey As RegistryKey
Try
regkey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings")
regkey.SetValue("ProxyServer", ServerName, RegistryValueKind.Unknown)
regkey.SetValue("ProxyEnable", True, RegistryValueKind.DWord)
regkey.Close()
Catch ex As Exception
MessageBox.Show("Error 04X: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
globalProxy_apply()
End Sub
Private Sub B_Set_Click(sender As System.Object, e As System.EventArgs) Handles B_Set.Click
If TextBox1.Text = "" Then
globalProxy_DisableProxy()
Else
globalProxy_SetProxy(TextBox1.Text)
End If
End Sub
Private Sub B_Disable_Click(sender As System.Object, e As System.EventArgs) Handles B_Disable.Click
globalProxy_DisableProxy()
End Sub
Private Sub B_Get_Click(sender As System.Object, e As System.EventArgs) Handles B_Get.Click
If globalProxy_IsProxyEnabled() Then
TextBox1.Text = globalProxy_GetProxyServer()
Else
TextBox1.Text = ""
End If
End Sub
End Class