[英]Webbrowser Each Control different proxy
I wanted to know whether it is possible to set proxy for each different webbrowser in an application (same process). 我想知道是否可以为应用程序中的每个不同的Web浏览器设置代理(相同的过程)。
I have searched a lot to find codes to change proxy system wide by modifying registry and another process specific proxy. 我已经进行了大量搜索,以找到通过修改注册表和其他特定于进程的代理来更改整个代理系统的代码。 But i want each webbrowser inside same process to have different proxy
但是我希望同一进程内的每个Web浏览器都具有不同的代理
Eg: WebBrowser1 Proxy --> 95.188.106.78:3128 例如:WebBrowser1代理-> 95.188.106.78:3128
WebBrowser 2 Proxy --> 89.218.160.162:9090 WebBrowser 2代理-> 89.218.160.162:9090
WebBrowser 3 Proxy --> 78.39.68.145:3128 and so on WebBrowser 3代理-> 78.39.68.145:3128等
Or if it is not possible by using WebBrowser directly, then can anyone else suggest what can i use to achieve this (not webrequests, i want browser only through which i can load all data and user can interact with it but with different proxies) like using geckofx or webkit? 或者,如果无法通过直接使用WebBrowser来实现,那么其他人能否建议我可以使用什么来实现此目的(不是Webrequests,我只希望浏览器可以加载所有数据,并且用户可以与之交互但可以使用不同的代理进行交互),例如使用geckofx还是webkit? But i don't know if its possible in them or not
但是我不知道它们是否可能
Unfortunately, you cannnot set the proxy per insnance. 不幸的是,您不能为每个实例设置代理。 Not even per application - it is global.
甚至不是每个应用程序-它是全局的。 If you chnage it for a .net app, it will impact IE as well.
如果为.net应用程序更改它,它也会影响IE。
Here is complete code to change the proxy. 这是更改代理的完整代码。
Create a "Form1" with buttons "B_Get" "B_Set" and "B_Disable" and then paste this code. 使用按钮“ B_Get”,“ B_Set”和“ B_Disable”创建“ Form1”,然后粘贴此代码。
It should work for you. 它应该为您工作。 I used this app as proof of concept for an automatic proxy cycler i built.
我用这个程序作为我构建的自动代理循环程序的概念证明。
Depending on your applications needs, you may be able to switch it, and then switch it back. 根据您的应用程序需求,您可以将其切换,然后再切换回去。 Note that it WILL impact internet explorer.
请注意,它将影响Internet Explorer。
To verify that this is working, check internet explorer. 要验证它是否正常运行,请检查Internet Explorer。 You will probably have to open/close the options dialog for IE, but you shouldnt need to restart the browser.
您可能必须打开/关闭IE的选项对话框,但不必重新启动浏览器。
This will also impact .NET apps on the fly - if you run my program while yours is running, you will be able to change the proxy that your program is using. 这也将动态影响.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.