AMH
AMH

Reputation: 6451

.NET: Determining the URL of proxy

I want to pass the proxy to my web service. I found the following code

MyWebService myService = new MyWebService(); 
System.Net.WebProxy proxyObject = 
    new System.Net.WebProxy("http://proxyserver:80/", true); 
myService.Proxy = proxyObject;  
myService.MyMethod();

How do I get "http://proxyserver:80/" dynamically?

Upvotes: 0

Views: 175

Answers (1)

Dyppl
Dyppl

Reputation: 12381

Try this:

 IWebProxy proxy = WebRequest.GetSystemWebProxy();
 proxy.Credentials = CredentialCache.DefaultCredentials;
 webRequest.Proxy = proxy;

The GetSystemWebProxy method reads the system proxy settings set up in Internet Explorer options. If that's not what you want, I'm afraid there is no way to automagically determine the address of some unknown proxy server.

Upvotes: 1

Related Questions