c#httpclient 代理_HttpClient.DefaultProxy 属性 (System.Net.Http) | Microsoft Docs

获取或设置全局 HTTP 代理。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; }

member this.DefaultProxy : System.Net.IWebProxy with get, set

Public Shared Property DefaultProxy As IWebProxy

属性值

用于实例化的每个调用所使用的代理 HttpWebRequest 。A proxy used by every call that instantiates a HttpWebRequest.

例外

传递的值不能为 null。The value passed cannot be null.

注解

HttpClient   如果在  HttpClientHandler 通过其构造函数传递的中未显式设置代理,则此静态属性将确定所有实例都使用的默认代理。This static property determines the default proxy that all HttpClient instances use if no proxy is set explicitly in the HttpClientHandler passed through its constructor.

此属性返回的默认实例将根据你的平台,初始化以下一组不同的规则:The default instance returned by this property will initialize following a different set of rules depending on your platform:

对于 Windows: 从环境变量中读取代理配置,或者从用户的代理设置中读取代理配置(如果未定义)。For Windows: Reads proxy configuration from environment variables or, if those are not defined, from the user's proxy settings.

对于 macOS: 从环境变量中读取代理配置,如果未定义,则从系统的代理设置中读取。For macOS: Reads proxy configuration from environment variables or, if those are not defined, from the system's proxy settings.

对于 Linux: 从环境变量读取代理配置,或者,如果未定义这些配置,此属性将初始化绕过所有地址的非配置实例。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.

用于 DefaultProxy 在 Windows 和基于 Unix 的平台上进行初始化的环境变量包括:The environment variables used for DefaultProxy initialization on Windows and Unix-based platforms are:

HTTP_PROXY: HTTP 请求上使用的代理服务器。HTTP_PROXY: the proxy server used on HTTP requests.

HTTPS_PROXY:对 HTTPS 请求使用的代理服务器。HTTPS_PROXY: the proxy server used on HTTPS requests.

ALL_PROXY:未定义 HTTP_PROXY 和/或 HTTPS_PROXY 时,在 HTTP 和/或 HTTPS 请求上使用的代理服务器。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:应从代理中排除的主机名的逗号分隔列表。NO_PROXY: a comma-separated list of hostnames that should be excluded from proxying.

在环境变量区分大小写的系统上,变量名称可以全部小写或全部大写。On systems where environment variables are case-sensitive, the variable names may be all lowercase or all uppercase. 首先检查小写名称。The lowercase names are checked first.

代理服务器可以是主机名或 IP 地址,可以后跟冒号和端口号,也可以是 http URL (可选),其中包括用于代理身份验证的用户名和密码。The proxy server may be a hostname or IP address, optionally followed by a colon and port number, or it may be an http URL, optionally including a username and password for proxy authentication. URL 必须以开头,而 http 不 https 能在主机名、IP 或端口后面包含任何文本。The URL must be start with http, not https, and cannot include any text after the hostname, IP, or port.

适用于

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值