C# WebBrowser 控件代理

标签 c# proxy webbrowser-control

如何在 C# WebBrowser 控件/组件中实现代理。

我想知道的是如何实现代理,所以我的 C# webBrowser 控件在运行时使用此代理进行浏览。

我也不想通过注册表更改代理...因为它会影响我的正常浏览...

最佳答案

private Uri currentUri;

        private void Form1_Load(object sender, EventArgs e)
        {
            currentUri = new Uri(@"http://www.stackoverflow.com");
            HttpWebRequest myRequest = (HttpWebRequest) HttpWebRequest.Create("http://www.stackoverflow.com");
            //WebProxy myProxy = new WebProxy("208.52.92.160:80");
            //myRequest.Proxy = myProxy;

            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

            webBrowser1.DocumentStream = myResponse.GetResponseStream();

            webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
        }

        void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (e.Url.AbsolutePath != "blank")
            {
                currentUri = new Uri(currentUri, e.Url.AbsolutePath);
                HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(currentUri);

                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

                webBrowser1.DocumentStream = myResponse.GetResponseStream();
                e.Cancel = true;
            }
        }

您需要尝试一下,但我可以浏览该站点。

或者您可以尝试修改 WebRequest.DefaultWebProxy 设置: http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx

关于C# WebBrowser 控件代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9035911/

相关文章:

c# - 常见做法 - SplitContainer

nginx - 使用 Ansible 在 Docker 中设置 Nginx 代理

java - hibernate 环境 : Initializing Envers Proxies

c# - WebBrowser 控件和 Wininet API

c# - 线程、进程和 Application.Exit()

c# - WPF ListBox 模板绑定(bind)仅在滚动时更新

Php通过代理请求

c# - WPF WebBrowser.Document 属性实际返回哪个对象?

c# - 获取Webbrowser Control中URL的原始源代码

c# - xsd 生成器到 C#/protobuf