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.
void CheckAutoGlobalProxyForRequest( Uri^ resource )
{
   WebProxy^ proxy = gcnew 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, resourceProxy );
   }
}
// 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 プロパティが返されます。

適用対象