HttpWebRequest one proxy and one not

How do I proxy my connections? I want 3 default HttpWebRequest objects that won't go through the proxy and 3 more that does. I am doing WebRequestObject.Proxy = myProxy; on objects I want to use a proxy server and do nothing on 3 objects, am I not doing this? also the objects will be initialized in an unknown order, so I can have 2 no, 2 which is proxied, the third which is not and final. Is this just a .Proxy = myProxy entry?

+5
source share
3 answers

For requests that require a proxy server, yes, this will work fine:

request.Proxy = myProxy;

, -, :

request.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy;

- IE ( - /web.config), - null:

request.Proxy = null;

HttpWebRequest.Proxy GetEmptyWebProxy .

+10

System.Net.GlobalProxySelection.GetEmptyWebProxy .

    private static void SetProxy(HttpWebRequest request)
    {
        if (AppConstants.UseProxyCredentials)
        {
            //request.Proxy = available in System.Net configuration settings
            request.Proxy.Credentials = Credentials.GetProxyCredentials();
        }
        else
        {
            request.Proxy = null;
            //request.Proxy.Credentials = n/a
        }
    }

web.config:

<system.net>
  <defaultProxy>
    <proxy
      autoDetect="False"
      bypassonlocal="True"
      scriptLocation="http://www.proxyscript..."
      proxyaddress="http://proxyurl..." />
  </defaultProxy>
</system.net>
<system.web>
+3

, - , , , . , , - system.net app.config.

+2
source

All Articles