I'm trying to get a proxy for a web request (HttpWebRequest or webclient) In the control panel-> Internet Options-> Connections-> LAN Settings, you will see 3 options:
- Auto detect settings
- Use automatic script configuration
- Use proxy server for LAN
I want to make sure that no matter what setting is set, my web request takes the same proxy as the browser.
I use the code below to achieve this; however, when 1. is checked, I try to use the same URL in the browser and my code, it looks like my code is much slower. I suggest that the way to get proxies in code may be inefficient or appropriate.
Is there anything I can change in my code to display browser speed?
var client = (HttpWebRequest)WebRequest.Create(uriStr); client.Headers["something"] = something; client.Timeout = ConnectionTimeOut; //1 min var proxyURI = WebRequest.GetSystemWebProxy().GetProxy(uri); var proxy = new WebProxy(proxyURI, true) { Credentials = CredentialCache.DefaultNetworkCredentials }; //if there is no proxy, proxy will return the same uri //do we need check if client.Proxy is null or not, if (proxyURI != null && !string.IsNullOrEmpty(proxyURI.AbsoluteUri) && !proxy.Address.Equals(uri)) { client.Proxy = proxy; }
source share