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 die WebRequest Instanz zum Zugreifen auf die Internetressource verwendet.

GetProxy vergleicht destination mit dem Inhalt von BypassList, mit der IsBypassed Methode. Wenn IsBypassed zurückgegeben true, GetProxy zurückgegeben destination wird und die WebRequest Instanz den Proxyserver nicht verwendet.

Wenn destination dies nicht der BypassListFall ist, verwendet die WebRequest Instanz den Proxyserver, und die Address Eigenschaft wird zurückgegeben.

Gilt für: