Language

WebProxy.GetProxy(Uri) メソッド

定義

要求のプロキシ化された URI を返します。

public:
 virtual Uri ^ GetProxy(Uri ^ destination);
public Uri? GetProxy(Uri destination);
public Uri GetProxy(Uri destination);
abstract member GetProxy : Uri -> Uri
override this.GetProxy : Uri -> Uri
Public Function GetProxy (destination As Uri) As Uri

パラメーター

destination
Uri

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

返品

Uri

リソースがバイパス リストにある場合はインターネット リソースの Uri インスタンス。それ以外の場合はプロキシの Uri インスタンス。

実装

例外

destination パラメーターはnull。

例

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

// 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 を返します。

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

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

適用対象