GlobalProxySelection.GetEmptyWebProxy Método

Definição

Retorna uma instância do proxy vazio.Returns an empty proxy instance.

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

Retornos

IWebProxy

Um IWebProxy que não contém informações.An IWebProxy that contains no information.

Exemplos

O exemplo de código a seguir cria uma WebRequest instância que não usa um proxy.The following code example creates a WebRequest instance that does not use a proxy.

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

Comentários

O GetEmptyWebProxy método retorna uma instância em branco IWebProxy para indicar que nenhum proxy é usado para acessar um recurso da Internet.The GetEmptyWebProxy method returns a blank IWebProxy instance to indicate that no proxy is used to access an Internet resource.

Em vez de chamar o GetEmptyWebProxy método, você pode atribuir null a membros como a WebClient.Proxy propriedade, que especifica o proxy que se comunica com servidores remotos em nome do WebClient objeto.Instead of calling the GetEmptyWebProxy method, you can assign null to members such as the WebClient.Proxy property, which specifies the proxy that communicates with remote servers on behalf of the WebClient object.

Aplica-se a