GlobalProxySelection.GetEmptyWebProxy 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回空代理实例。
public:
static System::Net::IWebProxy ^ GetEmptyWebProxy();
public static System.Net.IWebProxy GetEmptyWebProxy ();
static member GetEmptyWebProxy : unit -> System.Net.IWebProxy
Public Shared Function GetEmptyWebProxy () As IWebProxy
返回
不包含信息的 IWebProxy。
示例
下面的代码示例创建不使用 WebRequest 代理的实例。
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::IO;
int main()
{
// Create a request for the Web page at www.contoso.com.
WebRequest^ request = WebRequest::Create( L"http://www.contoso.com" );
// This application doesn't want they proxy to be used so it sets
// the global proxy to an empy proxy.
IWebProxy^ myProxy = GlobalProxySelection::GetEmptyWebProxy();
// Get the response.
WebResponse^ response = request->GetResponse();
// Display the response to the console.
Stream^ stream = response->GetResponseStream();
StreamReader^ reader = gcnew StreamReader( stream );
Console::WriteLine( reader->ReadToEnd() );
// Clean up.
reader->Close();
stream->Close();
response->Close();
return 0;
}
using System;
using System.Net;
using System.IO;
namespace Examples.Http
{
public class TestGlobalProxySelection
{
public static void Main()
{
// Create a request for the Web page at www.contoso.com.
WebRequest request = WebRequest.Create("http://www.contoso.com");
// This application doesn't want the proxy to be used so it sets
// the global proxy to an empty proxy.
IWebProxy myProxy = GlobalProxySelection.GetEmptyWebProxy();
GlobalProxySelection.Select = myProxy;
// Get the response.
WebResponse response = request.GetResponse();
// Display the response to the console.
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
Console.WriteLine(reader.ReadToEnd());
// Clean up.
reader.Close();
stream.Close();
response.Close();
}
}
}
注解
方法 GetEmptyWebProxy 返回一个空白 IWebProxy 实例,指示没有代理用于访问 Internet 资源。
可以分配给 null
成员(如 WebClient.Proxy 属性),而不是调用 GetEmptyWebProxy
方法,该属性指定代表 对象与远程服务器通信的WebClient代理。