Using proxy with WebBrowser and WebRequest, how to include username and password?

烂漫一生 提交于 2021-02-10 15:53:59

问题


I got this from Load web browser with web response. and am wondering how I can use this code to use proxies that need a username and password to be able to work.

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:


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


来源:https://stackoverflow.com/questions/11161434/using-proxy-with-webbrowser-and-webrequest-how-to-include-username-and-password

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!