How to get a proxy server

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; } 
+4
source share
1 answer

Your approach is wonderful.

What could be causing the speed difference is that the browser can either cache the requested page, or cache the credentials of the proxy server and proxy server, and you don’t need to make any clean new settings that you make in your code .

Have you tried to execute subsequent requests in your application after receiving proxy / credentials?

+2
source

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


All Articles