WebProxy.GetProxy(Uri) Methode

Definition

Gibt den Proxy-URI einer Anforderung zurück.

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

Parameter

destination
Uri

Die Uri-Instanz der angeforderten Internetressource.

Gibt zurück

Uri

Die Uri-Instanz der Internetressource, wenn die Ressource in der Umgehungsliste aufgeführt ist, andernfalls die Uri-Instanz des Proxys.

Implementiert

Ausnahmen

Der destination-Parameter ist null.

Beispiele

Im folgenden Codebeispiel wird ein WebProxy -Objekt erstellt und diese Methode aufgerufen, um den proxy abzurufen, der für eine Ressource ausgewählt ist.

// 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());
    }
}

Hinweise

Die GetProxy -Methode gibt den URI zurück, den der HttpClient instance für den Zugriff auf die Internetressource verwendet.

GetProxy vergleicht destination mit dem Inhalt von BypassListmithilfe der IsBypassed -Methode. Wenn IsBypassed zurückgibttrue, GetProxy wird zurückgegebendestination, und der HttpClient instance verwendet nicht den Proxyserver.

Wenn destination nicht in BypassListvorhanden ist, verwendet der HttpClient instance den Proxyserver, und die Address -Eigenschaft wird zurückgegeben.

Gilt für: