Bagikan melalui


GlobalProxySelection.GetEmptyWebProxy Metode

Definisi

Mengembalikan instans proksi kosong.

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

Mengembalikan

Yang IWebProxy tidak berisi informasi.

Contoh

Contoh kode berikut membuat instans WebRequest yang tidak menggunakan proksi.

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();
        }
    }
}

Keterangan

Metode mengembalikan GetEmptyWebProxy instans kosong IWebProxy untuk menunjukkan bahwa tidak ada proksi yang digunakan untuk mengakses sumber daya Internet.

Alih-alih memanggil GetEmptyWebProxy metode , Anda dapat menetapkan null ke anggota seperti WebClient.Proxy properti , yang menentukan proksi yang berkomunikasi dengan server jarak jauh atas WebClient nama objek.

Berlaku untuk