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

Mon*_*RPG 5 c# browser proxy webbrowser-control

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

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

bre*_*dan 5

浏览器控件只是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);
Run Code Online (Sandbox Code Playgroud)

请参阅: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浏览器控制功能于net.aspx