WebProxy.GetDefaultProxy 方法

定义

注意

This method has been deprecated. Please use the proxy selected for you by default. https://go.microsoft.com/fwlink/?linkid=14202

注意

WebProxy.GetDefaultProxy has been deprecated. Use the proxy selected for you by default.

注意

This method has been deprecated. Please use the proxy selected for you by default. http://go.microsoft.com/fwlink/?linkid=14202

读取 Internet 选项非动态代理设置。

public:
 static System::Net::WebProxy ^ GetDefaultProxy();
[System.Obsolete("This method has been deprecated. Please use the proxy selected for you by default. https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.WebProxy GetDefaultProxy ();
[System.Obsolete("WebProxy.GetDefaultProxy has been deprecated. Use the proxy selected for you by default.")]
public static System.Net.WebProxy GetDefaultProxy ();
[System.Obsolete("This method has been deprecated. Please use the proxy selected for you by default. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.WebProxy GetDefaultProxy ();
public static System.Net.WebProxy GetDefaultProxy ();
[<System.Obsolete("This method has been deprecated. Please use the proxy selected for you by default. https://go.microsoft.com/fwlink/?linkid=14202")>]
static member GetDefaultProxy : unit -> System.Net.WebProxy
[<System.Obsolete("WebProxy.GetDefaultProxy has been deprecated. Use the proxy selected for you by default.")>]
static member GetDefaultProxy : unit -> System.Net.WebProxy
[<System.Obsolete("This method has been deprecated. Please use the proxy selected for you by default. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member GetDefaultProxy : unit -> System.Net.WebProxy
static member GetDefaultProxy : unit -> System.Net.WebProxy
Public Shared Function GetDefaultProxy () As WebProxy

返回

包含 WebProxy Internet 选项中的非动态代理设置的 实例。

属性

例外

在 .NET Core 上。

示例

下面的代码示例演示如何调用此方法。

void CheckDefaultProxyForRequest( Uri^ resource )
{
   WebProxy^ proxy = (WebProxy^)( WebProxy::GetDefaultProxy() );
   
   // See what proxy is used for 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 );
   }
}
public static void CheckDefaultProxyForRequest(Uri resource)
{
    WebProxy proxy = (WebProxy) WebProxy.GetDefaultProxy();

    // See what proxy is used for 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.ToString(),
            resourceProxy.ToString());
    }
}

注解

方法 GetDefaultProxy 从计算机的 Internet 选项中读取非动态代理设置,并使用这些设置创建实例 WebProxy

方法 GetDefaultProxy 不会从 Internet Explorer 运行的脚本、自动配置条目或 DHCP 或 DNS 查找中获取任何动态设置。

应用程序应使用 HttpClient.DefaultProxy 属性而不是 GetDefaultProxy 方法。

注意

.NET Core 不支持此属性。

适用于