Configure a proxy

Updated at:
Copy as MD

You can route .NET SDK V2.0 requests through an HTTP or HTTPS proxy for access control, logging, or caching. Configure the proxy at the client level for all requests or at the request level using runtime options.

Proxy types

HTTP and HTTPS proxies are supported. You can use either type in your application.

Proxy type

Description

HTTP proxy

Configure the proxy server address and port using the HttpProxy parameter. The format is http://<IP address>:<port>. This applies only to HTTP requests.

HTTPS proxy

Configure the proxy server address and port using the HttpsProxy parameter. The format is http://<IP address>:<port>.

Note

If the proxy server requires authentication, add the username and password to the address. The format is http://<user>:<password>@<IP address>:<port>.

Proxy configuration methods

Note

If both are set, the RuntimeOptions proxy configuration takes precedence over the client-level configuration.

  • Configure a proxy for a single request by using AlibabaCloud.TeaUtil.Models.RuntimeOptions.

    // Runtime parameter settings. These settings apply only to requests that use this RuntimeOptions instance.
    var runtimeOptions = new AlibabaCloud.TeaUtil.Models.RuntimeOptions
    {
        HttpProxy = "http://127.0.0.1:9898";
        HttpsProxy = "http://127.0.0.1:8989";
    };
    
  • Configure a proxy for all requests by using AlibabaCloud.OpenApiClient.Models.Config.

    var config = new AlibabaCloud.OpenApiClient.Models.Config
    {
        // Proxy parameter settings. These settings apply to all clients that use this config.
        HttpProxy = "http://127.0.0.1:9898",
        HttpsProxy = "http://127.0.0.1:8989"
    };
    

References

For the complete HTTP proxy setup, see HTTP proxy configuration.