Get IE default proxy using DefaultWebProxy

I read almost all the documentation I can find, but I have not yet found a simple working example of how to get IE proxy settings by default using DefaultWebProxy() .

This code seems to compile and work, but how can I continue and get the proxy URI as a string?

 HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.google.com"); if (WebRequest.DefaultWebProxy != null) { webRequest.Proxy = WebRequest.DefaultWebProxy; } 

EDIT:

Since submitting this question, I have found that one or more proxies can be set for different destinations or bypassed (possibly for local places on the intranet). Therefore, you need to specify a URI for GetProxy() . He should know what destination the proxy server is for. If the “Automatically detect settings” is set in the “Internet Options” window, the browser will search for the PAC file in your local domain. The PAC file contains a Javascript function that determines the proxy address for this destination.

+4
source share
1 answer

WebRequest.DefaultWebProxy implements the IWebProxy interface. You can use the GetProxy method to get the proxy URI:

 var uri = WebRequest.DefaultWebProxy.GetProxy(new Uri("http://www.google.com")); 

Reply to comment:

You need to pass uri to GetProxy because this is how Microsoft implemented it ...

Seriously, I believe this is because you can configure the browser to bypass proxies for some addresses. If you go through one of these bypassed addresses, you are likely to get a different result.
+5
source

Source: https://habr.com/ru/post/1485914/


All Articles