user1455112
user1455112

Reputation: 183

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

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;    

Upvotes: 1

Views: 2161

Answers (1)

Baz1nga
Baz1nga

Reputation: 15579

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

Upvotes: 3

Related Questions