[英]Using Webbrowser control with Web proxy servers dynamically with C#
[英]C# WebBrowser Control Proxy
如何在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.