英語で読む

次の方法で共有


WebProxy.GetProxy(Uri) メソッド

定義

要求に対するプロキシの URI を返します。

C#
public Uri? GetProxy(Uri destination);
C#
public Uri GetProxy(Uri destination);

パラメーター

destination
Uri

要求されたインターネット リソースの Uri インスタンス。

戻り値

Uri

インターネット リソースがバイパス一覧に含まれている場合は、そのリソースの Uri インスタンス。それ以外の場合はプロキシの Uri インスタンス。

実装

例外

destination パラメーターが null です。

次のコード例では、 オブジェクトを WebProxy 作成し、このメソッドを呼び出して、リソースに対して選択されたプロキシを取得します。

C#
// The following method creates a WebProxy object that uses Internet Explorer's
// detected script if it is found in the registry; otherwise, it
// tries to use Web proxy auto-discovery to set the proxy used for
// the request.

public static void CheckAutoGlobalProxyForRequest(Uri resource)
{
    WebProxy proxy = new WebProxy();

    // Display the proxy's properties.
    DisplayProxyProperties(proxy);

    // See what proxy is used for the resource.
    Uri resourceProxy = proxy.GetProxy(resource);

    // Test to see whether a proxy was selected.
    if (resourceProxy == resource)
    {
        Console.WriteLine("No proxy for {0}", resource);
    }
    else
    {
        Console.WriteLine("Proxy for {0} is {1}", resource.OriginalString,
            resourceProxy.ToString());
    }
}

注釈

メソッドは GetProxy 、インスタンスが HttpClient インターネット リソースへのアクセスに使用する URI を返します。

GetProxydestination 、 メソッドを使用して の BypassList内容と比較します IsBypassed 。 が を返す GetProxytrue場合IsBypassedは がdestination返され、HttpClientインスタンスはプロキシ サーバーを使用しません。

が でないBypassList場合destination、インスタンスはHttpClientプロキシ サーバーを使用し、 Address プロパティが返されます。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1