WebProxy.GetProxy(Uri) Método

Definição

Retorna o URI com proxy para uma solicitação.

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

A instância Uri do recurso solicitado da Internet.

Retornos

Uri

A instância Uri do recurso da Internet, se o recurso estiver na lista de ignoráveis; caso contrário, a instância Uri do proxy.

Implementações

Exceções

O parâmetro destination é null.

Exemplos

O exemplo de código a seguir cria um WebProxy objeto e chama esse método para obter o proxy selecionado para um 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());
    }
}

Comentários

O GetProxy método retorna o URI que a HttpClient instância usa para acessar o recurso da Internet.

GetProxydestination compara com o conteúdo de BypassList, usando o IsBypassed método . Se IsBypassed retornar true, GetProxy retornará destination e a HttpClient instância não usará o servidor proxy.

Se destination não estiver em BypassList, a HttpClient instância usará o servidor proxy e a Address propriedade será retornada.

Aplica-se a