WebProxy.GetProxy(Uri) Metoda

Definicja

Zwraca identyfikator URI proxied dla żądania.

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

Parametry

destination
Uri

Wystąpienie Uri żądanego zasobu internetowego.

Zwraca

Uri

Wystąpienie Uri zasobu internetowego, jeśli zasób znajduje się na liście obejścia; w przeciwnym razie Uri wystąpienie serwera proxy.

Implementuje

Wyjątki

Parametr destination to null.

Przykłady

Poniższy przykład kodu tworzy obiekt i wywołuje tę metodę WebProxy w celu pobrania serwera proxy wybranego dla zasobu.

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

Uwagi

Metoda GetProxy zwraca identyfikator URI używany HttpClient przez wystąpienie do uzyskiwania dostępu do zasobu internetowego.

GetProxy porównuje destination się z zawartością BypassListmetody , przy użyciu IsBypassed metody . Jeśli IsBypassed zwraca truewartość , zwraca wartość destination , GetProxy a HttpClient wystąpienie nie używa serwera proxy.

Jeśli destination nie znajduje się w BypassListprogramie , HttpClient wystąpienie używa serwera proxy, a Address właściwość jest zwracana.

Dotyczy