浏览器导航未通过代理连接 [英] Browser navigation not connecting through a proxy

查看:116
本文介绍了浏览器导航未通过代理连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过代理连接到互联网,更具体地说,此网站用于测试代理是否正常工作 AZ环境变量1.04 你可以在下面看到..它不是使用我设置的代理连接,正如你在下面的代码中看到的,它应该是..我使用调试器,一切都很好,它是流经代码它的方式。



为什么

 webBrowser1.Navigate(browserNavigationTxtBox.Text); 

不使用代理地址我也在

 proxyBox.Text中设置了





图片显示了最新情况。 />
http://i.stack.imgur.com/ek2Lq.png [ ^ ]







 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
使用 System.Management;
使用 System.Net;
使用 Fiddler;
使用 Fiddler.WebFormats;

命名空间 Switch_IP
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}

private Uri currentUri;

private void Form1_Load( object sender,EventArgs e)
{
currentUri = new Uri(browserNavigationTxtBox.Text);
HttpWebRequest myRequest =(HttpWebRequest)HttpWebRequest.Create(browserNavigationTxtBox.Text);
var myProxy = new WebProxy(proxyBox.Text);
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!= browserNavigationTxtBox.Text)
{
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 ;
}
}

私人 void Start_Click( object sender,EventArgs e)
{
webBrowser1.Navigate(browserNavigationTxtBox.Text);

}
}
}





我尝试过:



基本上我所尝试过的都是代码中的什么,它在开头看起来有点不同,代码很乱

解决方案

您没有在webBrowser1_Navigating事件处理程序中设置代理服务器,只在Form_Load事件处理程序中设置

将代码添加到 webBrowser1_Navigating 使您的HttpWebRequest使用代理的事件处理程序

 WebProxy myProxy =  WebProxy(proxyBox。文本); 
myRequest.Proxy = myProxy;



在Form_Load中,您创建了一个HttpWebRequest&设置代理

在WebBrowser导航事件处理程序中,您创建了另一个HttpWebRequest但尚未设置代理服务器..



亲切问候


I am trying to connect to the internet through a proxy, more specificlly, this site to test if the proxy is working AZ Environment variables 1.04 As you can see down below.. It is NOT connecting using the proxy I set it to, and as you can see in the code below, it should be.. I used the debugger, everything was fine, it was flowing through the code the way it should.

Why is the

webBrowser1.Navigate(browserNavigationTxtBox.Text);

not using the proxy address I set it too in

proxyBox.Text



Image showing whats going on.
http://i.stack.imgur.com/ek2Lq.png[^]



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Net;
using Fiddler;
using Fiddler.WebFormats;

namespace Switch_IP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Uri currentUri;

        private void Form1_Load(object sender, EventArgs e)
        {
            currentUri = new Uri(browserNavigationTxtBox.Text);
            HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(browserNavigationTxtBox.Text);
            var myProxy = new WebProxy(proxyBox.Text);
            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 != browserNavigationTxtBox.Text)
            {
                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;
            }
        }

        private void Start_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(browserNavigationTxtBox.Text);

        }
    }
}



What I have tried:

Basically all I've tried is whats in the code, it looked alot different in the beginning, the code was a big mess

解决方案

You are not setting your Proxy server in the webBrowser1_Navigating event handler, only in your Form_Load event handler
Add the code to the webBrowser1_Navigating event handler to make your HttpWebRequest use the Proxy

WebProxy myProxy = new WebProxy(proxyBox.Text);
myRequest.Proxy = myProxy;


In Form_Load you have created a HttpWebRequest & set the Proxy
In the WebBrowser Navigating event handler you have created another HttpWebRequest but have not set the proxy server..

Kind Regards


这篇关于浏览器导航未通过代理连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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