How do I use a socket proxy in C# webbrowser?

2019-08-20 01:24发布

问题:

How do I point a socket to the proxy ip/port using the winforms webbrowser control? The standard web browser that comes with Visual C#.NET.

Please help in Visual C#.NET.

回答1:

The WebBrowser control is just a wrapper around IE. So to set proxy settings, you could change the registry key entries.

Something like this:

string serverName = ""; // your proxy server name
string port = ""; // your proxy port

var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
key.SetValue("ProxyServer", serverName + ":" + port);
key.SetValue("ProxyEnable", 1);


回答2:

WebBrowser is just an interface over IE. To set the IE proxy settings, you can hack the registry!

        string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
        string serverName = "";//your proxy server name;
        string port = ""; //your proxy port;
        string proxy = serverName + ":" + port;

        RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
        RegKey.SetValue("ProxyServer", proxy);
        RegKey.SetValue("ProxyEnable", 1);