如何在C#应用程序中使用代理 [英] How to use proxy with C# application

查看:298
本文介绍了如何在C#应用程序中使用代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Visual Studio 2010 C#.net 4.0

I am using Microsoft Visual Studio 2010 C# .net 4.0

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

I have a webbrowser element. What i want to do is navigating via Webbrowser element with using proxy. How can i do that ? thank you.

推荐答案

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

The browser control is just an instance of IE - it will use IE's proxy settings. You can set these by playing with registry keys if you must do it in code.

        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-webbrowser-control-in-net.aspx

Update: Looks like this can be done for just the control and not the entire machine. See this code sample for setting the proxy for just a single process - http://blogs.msdn.com/b/jpsanders/archive/2011/04/26/how-to-set-the-proxy-for-the-webbrowser-control-in-net.aspx

这篇关于如何在C#应用程序中使用代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆