WebProxy.GetProxy(Uri) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回请求的已代理 URI。
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
参数
返回
如果资源在回避列表上,则为 Internet 资源的 Uri 实例;否则为代理的 Uri 实例。
实现
例外
destination
参数为 null
。
示例
下面的代码示例创建一个 WebProxy 对象,并调用此方法以获取为资源选择的代理。
// 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());
}
}
注解
方法 GetProxy 返回实例用于访问 Internet 资源的 URI HttpClient 。
GetProxy使用 destination
IsBypassed 方法与 的内容BypassList进行比较。 如果 IsBypassed 返回 true
, GetProxy 则 destination
返回 ,并且 HttpClient 实例不使用代理服务器。
如果 destination
不在 中 BypassList,则 HttpClient 实例使用代理服务器并 Address 返回 属性。