Język

NSUrlSessionHandler.Proxy Property

Definition

The proxy to use for requests.

public System.Net.IWebProxy? Proxy { get; set; }
member this.Proxy : System.Net.IWebProxy with get, set

Property Value

The custom proxy to use, or null to use the proxies configured in the operating system.

Remarks

Setting this property only has an effect if UseProxy is true (which is the default value).

NSUrlSession applies proxy settings per-session, not per-request, so the proxy is evaluated only once, using the destination of the first request sent by this handler, and the result is applied to every subsequent request made by this handler.

This has important consequences when a single handler is reused for requests to multiple destinations: the proxy's per-destination decisions (IsBypassed(Uri) and the proxy returned by GetProxy(Uri)) are computed from the first request's destination only. As a result a proxy's bypass list and any destination-dependent proxy selection are not honored for later requests to other destinations: requests that should have been proxied might be sent directly (or through the wrong proxy), and requests that should have bypassed the proxy might be sent through it.

If per-destination proxy behavior is required, use a separate NSUrlSessionHandler (and thus a separate HttpClient) for each destination or proxy configuration.

Proxy authentication (using Proxy's own credentials or DefaultProxyCredentials) is only supported for HTTPS destinations (which are proxied using a CONNECT tunnel). For plain HTTP destinations NSUrlSession doesn't deliver a proxy authentication challenge, so proxy credentials aren't applied and an authenticating proxy will return an HTTP 407 response instead.

Applies to