GlobalProxySelection.GetEmptyWebProxy メソッド

定義

空白のプロキシ インスタンスを返します。

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

情報が格納されていない 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 のインスタンスを返します。

メソッドをGetEmptyWebProxy呼び出す代わりに、オブジェクトの代わりにWebClientリモート サーバーと通信するプロキシを指定するプロパティなどのWebClient.Proxyメンバーに割り当てることができますnull

適用対象