Upraviť

Zdieľať cez


HttpClient.DefaultProxy Property

Definition

Gets or sets the global HTTP proxy.

public:
 static property System::Net::IWebProxy ^ DefaultProxy { System::Net::IWebProxy ^ get(); void set(System::Net::IWebProxy ^ value); };
public static System.Net.IWebProxy DefaultProxy { get; set; }
static member DefaultProxy : System.Net.IWebProxy with get, set
Public Shared Property DefaultProxy As IWebProxy

Property Value

A proxy used by every HTTP request.

Exceptions

The value passed cannot be null.

Remarks

This static property determines the default proxy that all HttpClient instances use if no proxy is set explicitly in the HttpMessageHandler passed through its constructor.

The default instance returned by this property will initialize following a different set of rules depending on your platform:

  • For Windows: Reads proxy configuration from environment variables or, if those are not defined, from the user's proxy settings.

  • For macOS: Reads proxy configuration from environment variables or, if those are not defined, from the system's proxy settings.

  • For Linux: Reads proxy configuration from environment variables or, in case those are not defined, this property initializes a non-configured instance that bypasses all addresses.

The environment variables used for DefaultProxy initialization on Windows and Unix-based platforms are:

  • HTTP_PROXY: the proxy server used on HTTP requests.
  • HTTPS_PROXY: the proxy server used on HTTPS requests.
  • ALL_PROXY: the proxy server used on HTTP and/or HTTPS requests in case HTTP_PROXY and/or HTTPS_PROXY are not defined.
  • NO_PROXY: a comma-separated list of hostnames that should be excluded from proxying. Asterisks are not supported for wildcards; use a leading dot in case you want to match a subdomain. Examples: NO_PROXY=.example.com (with leading dot) will match www.example.com, but will not match example.com. NO_PROXY=example.com (without leading dot) will not match www.example.com. This behavior might be revisited in the future to match other ecosystems better.

On systems where environment variables are case-sensitive, the variable names may be all lowercase or all uppercase. The lowercase names are checked first.

The proxy server may be a hostname or IP address, optionally followed by a colon and port number, or it may be an http, https, socks4, socks4a, or socks5 URL. The URL cannot include any text after the hostname, IP, or port. If a scheme isn't specified, http is assumed. The URL may optionally include a username and password for proxy authentication, but the password is ignored when using socks4 or socks4a as the protocols have no support for password authentication.

  • http: http://[username:password@]hostname[:port]
  • https: https://[username:password@]hostname[:port]
  • socks4: socks4://[username@]hostname[:port]
  • socks4a: socks4a://[username@]hostname[:port]
  • socks5: socks5://[username:password@]hostname[:port]

Applies to