共用方式為


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 執行個體,否則為 Proxy 的 Uri 執行個體。

實作

例外狀況

destination 參數為 null

範例

下列程式代碼範例會 WebProxy 建立 物件並呼叫此方法,以取得為資源選取的 Proxy。

// 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 會傳回 實例用來存取因特網資源的 URI HttpClient

GetProxy destination使用 IsBypassed 方法,與的內容BypassList比較。 如果 IsBypassedtrue回 , GetProxy 則傳 destination 回 ,而且 HttpClient 實例不會使用 Proxy 伺服器。

如果 destination 不在 中 BypassListHttpClient 實例會使用 Proxy 伺服器,並 Address 傳回 屬性。

適用於