次の方法で共有


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

次のコード例では、プロキシを WebRequest 使用しないインスタンスを作成します。

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.Proxyメンバーに割り当てることができますnull。このプロパティは、オブジェクトの代わりにリモート サーバーと通信するプロキシをWebClient指定します。

適用対象