WebProxy.GetProxy(Uri) Método

Definición

Devuelve el identificador URI del proxy para una solicitud.

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

Parámetros

destination
Uri

La instancia de Uri del recurso de Internet solicitado.

Devoluciones

Uri

La instancia de Uri del recurso de Internet si el recurso se encuentra en la lista de omisiones; en caso contrario, la instancia de Uri del proxy.

Implementaciones

Excepciones

El parámetro destination es null.

Ejemplos

En el ejemplo de código siguiente se crea un WebProxy objeto y se llama a este método para obtener el proxy seleccionado para un recurso.

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

Comentarios

El GetProxy método devuelve el URI que la HttpClient instancia usa para acceder al recurso de Internet.

GetProxydestination compara con el contenido de BypassList, mediante el IsBypassed método . Si IsBypassed devuelve true, GetProxy devuelve destination y la HttpClient instancia no usa el servidor proxy.

Si destination no está en BypassList, la HttpClient instancia usa el servidor proxy y se devuelve la Address propiedad .

Se aplica a