0

There seem to be so many ways to create a WebProxy/IWebProxy and properties related to setting them. My question is: When I create a proxy, how do I actually use that proxy setting?

I can find options in WebRequest.DefaultWebProxy, WebRequest.GetSystemWebProxy(), WebRequest.Proxy, etc. to create and assign new WebProxy instances but this confuses me... Where would a program typically "grab" the specified proxy settings from?

Quick edit: I did notice that the HttpWebClientProtocol class seemed promising, but again, I'm not 100% sure as my proxy knowledge (and networking in general) is extremely limited...

Broots Waymb
  • 4,713
  • 3
  • 28
  • 51

1 Answers1

0

If you have created a HttpWebRequest object, you can asign it a proxy.

HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(myUrl);
string MyProxyHostString = "192.168.1.1";
int MyProxyPort = 3212;

//Here you asign the proxy to the HttpWebRequest 
myWebRequest.Proxy = new WebProxy(MyProxyHostString, MyProxyPort);
  • So if I set a (I'm assuming there are more types?) request, the application will go off of this specifically? If I were to do something like changing your line to something like `myWebRequest.Proxy = WebRequest.DefaultWebProxy`, it would use system defaults? – Broots Waymb Jul 15 '15 at 21:59
  • I found this http://stackoverflow.com/questions/8808052/c-sharp-getting-proxy-settings-from-internet-explorer You're using the `WebRequest()`, so you can use this option `WebRequest.DefaultProxy = WebRequest.GetSystemWebProxy();` – Johan Espinoza Jul 15 '15 at 22:11