2012-06-22 65 views
1

我從Load web browser with web response得到了這個。並想知道如何使用此代碼來使用需要用戶名和密碼才能工作的代理。在WebBrowser和WebRequest中使用代理,如何包含用戶名和密碼?

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;  

回答

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; 
相關問題