IWebProxy.GetProxy(Uri) Método

Definición

Devuelve el URI de un proxy.

public:
 Uri ^ GetProxy(Uri ^ destination);
public Uri GetProxy(Uri destination);
abstract member GetProxy : Uri -> Uri
Public Function GetProxy (destination As Uri) As Uri

Parámetros

destination
Uri

que Uri especifica el recurso de Internet solicitado.

Devoluciones

Uri

Instancia Uri de que contiene el URI del proxy usado para ponerse en contacto destinationcon ; de lo contrario, null o destination sí mismo.

Ejemplos

En el ejemplo siguiente se usa el GetProxy método para devolver el URI que usa HttpClient para acceder al recurso de Internet.

WebProxy_Interface webProxy_Interface = new WebProxy_Interface(new Uri("http://proxy.example.com"));

webProxy_Interface.Credentials = new NetworkCredential("myusername", "mypassword");

Uri testUri = new Uri("http://www.contoso.com");

// Determine whether the Web proxy can be bypassed for the site "http://www.contoso.com".
if(webProxy_Interface.IsBypassed(testUri))
{
    Console.WriteLine("Web Proxy is by passed");
}
else
{
    Uri? webProxyServer = webProxy_Interface.GetProxy(testUri);
    // In general, we wouldn't expect the condition (`webProxyServer! == testUri`) true here, if  IsBypassed returns `false`.
    // However, technically our interface can allow that.
    if (webProxyServer is null || webProxyServer! == testUri)
    {
        Console.WriteLine("Web proxy is bypassed");
    }
    else
    {
        Console.WriteLine("Web proxy is not bypassed");
        Console.WriteLine($"The web proxy is: {webProxyServer!}");
    }
}

 Public Shared Sub Main()
     Dim webProxy_Interface As New WebProxy_Interface(New Uri("http://proxy.example.com"))
     
     webProxy_Interface.Credentials = New NetworkCredential("myusername", "mypassword")
     
     Console.WriteLine("The web proxy is : {0}", webProxy_Interface.GetProxy(New Uri("http://www.contoso.com")))
     
     'Determine whether the Web proxy can be bypassed for the site "http://www.contoso.com".
 console.writeline("For the Uri http://www.contoso.com , the ")
     If webProxy_Interface.IsBypassed(New Uri("http://www.contoso.com")) Then
         Console.WriteLine("webproxy is by passed")
     Else
         Console.WriteLine("webproxy is not bypassed")
     End If 
 End Sub

Comentarios

El GetProxy método devuelve el URI del servidor proxy que controla las solicitudes al recurso de Internet especificado en el destination parámetro . Si el GetProxy método devuelve null o destination sí mismo, el proxy no se usa para ponerse en contacto con el host y la solicitud se pasa directamente al servidor.

Se aplica a