使用WebBrowser和WebRequest的代理,如何包含用户名和密码?

时间:2012-06-22 17:42:08

标签: c# proxy

我是从Load web browser with web response得到的。我想知道如何使用此代码来使用需要用户名和密码才能工作的代理。

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://example.com");
webRequest.Proxy = new WebProxy(host, port);

HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
Stream receiveStream = response.GetResponseStream();

WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentStream = receiveStream;    

1 个答案:

答案 0 :(得分:3)

var webProxy = new WebProxy(host,port);
webProxy.Credentials = new NetworkCredential("username", "password", "domain");
var webRequest = (HttpWebRequest)WebRequest.Create("http://example.com");
webRequest.Proxy = webProxy;