IWebProxy.GetProxy(Uri) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne l'URI d'un proxy.
public:
Uri ^ GetProxy(Uri ^ destination);
public Uri GetProxy (Uri destination);
public Uri? GetProxy (Uri destination);
abstract member GetProxy : Uri -> Uri
Public Function GetProxy (destination As Uri) As Uri
Paramètres
Retours
Instance Uri qui contient l’URI du proxy utilisé pour contacter destination
; sinon null ou destination
lui-même.
Exemples
L’exemple suivant utilise la GetProxy méthode pour renvoyer l’URI que le HttpClient utilise pour accéder à la ressource Internet.
WebProxy_Interface^ webProxy_Interface = gcnew WebProxy_Interface( gcnew Uri( "http://proxy.example.com" ) );
webProxy_Interface->Credentials = gcnew NetworkCredential( "myusername", "mypassword" );
Console::WriteLine( "The web proxy is : {0}", webProxy_Interface->GetProxy( gcnew Uri( "http://www.contoso.com" ) ) );
// Check if the webproxy can ne bypassed for the site "http://www.contoso.com".
if ( webProxy_Interface->IsBypassed( gcnew Uri( "http://www.contoso.com" ) ) )
{
Console::WriteLine( "Web Proxy is by passed" );
}
else
{
Console::WriteLine( "Web Proxy is not by passed" );
}
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
Remarques
La GetProxy méthode retourne l’URI du serveur proxy qui gère les requêtes à la ressource Internet spécifiée dans le destination
paramètre . Si la GetProxy méthode retourne null ou destination
elle-même, le proxy n’est pas utilisé pour contacter l’hôte et la demande est transmise directement au serveur.