如何在C#应用程序中使用代理

我使用的是Microsoft Visual Studio 2010 C#.net 4.0

我有一个webbrowser元素。 我想要做的是使用代理通过Webbrowser元素导航。 我怎样才能做到这一点 ? 谢谢。

浏览器控件只是IE的一个实例 – 它将使用IE的代理设置。 如果必须在代码中执行,可以通过使用注册表项来设置它们。

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); 

请参阅: http : //social.msdn.microsoft.com/forums/en-US/winforms/thread/da510380-9571-4fcd-a05f-b165ced45017/

更新 :看起来这只能用于控制而不是整个机器。 请参阅此代码示例,仅为单个进程设置代理 – http://blogs.msdn.com/b/jpsanders/archive/2011/04/26/how-to-set-the-proxy-for-the- web浏览器控制function于net.aspx

看到这个链接。 您可以轻松设置Web请求的代理,但WebBrowser类与iexplore.exe共享设置…如果需要,可以通过以编程方式更改IE注册表值来调整代理设置,然后将其更改回来(请参阅brendan的回答)。

如何在不影响SYSTEM / IE代理的情况下为Webbrowser Control设置代理