WebProxy.GetProxy(Uri) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the proxied URI for a request.
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
Parameters
Returns
The Uri instance of the Internet resource, if the resource is on the bypass list; otherwise, the Uri instance of the proxy.
Implements
Exceptions
The destination
parameter is null
.
Examples
The following code example creates a WebProxy object and calls this method to get the proxy that is selected for a resource.
// 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());
}
}
Remarks
The GetProxy method returns the URI that the HttpClient instance uses to access the Internet resource.
GetProxy compares destination
with the contents of BypassList, using the IsBypassed method. If IsBypassed returns true
, GetProxy returns destination
and the HttpClient instance does not use the proxy server.
If destination
is not in BypassList, the HttpClient instance uses the proxy server and the Address property is returned.