Condividi tramite


GlobalProxySelection.GetEmptyWebProxy Metodo

Definizione

Restituisce un'istanza di proxy vuota.

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

Restituisce

IWebProxy che non contiene informazioni.

Esempio

Nell'esempio di codice seguente viene creata un'istanza WebRequest che non usa un proxy.

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

Commenti

Il metodo restituisce un'istanza GetEmptyWebProxy vuota IWebProxy per indicare che non viene usato alcun proxy per accedere a una risorsa Internet.

Anziché chiamare il GetEmptyWebProxy metodo, è possibile assegnare null ai membri, ad esempio la WebClient.Proxy proprietà, che specifica il proxy che comunica con server remoti per conto dell'oggetto WebClient .

Si applica a