GlobalProxySelection.GetEmptyWebProxy Método
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Devuelve una instancia de proxy vacía.
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 que no contiene ninguna información.
En el ejemplo de código siguiente se crea una WebRequest instancia que no usa un 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();
}
}
}
El GetEmptyWebProxy método devuelve una instancia en blanco IWebProxy para indicar que no se usa ningún proxy para acceder a un recurso de Internet.
En lugar de llamar al GetEmptyWebProxy
método , puede asignar null
a miembros como la WebClient.Proxy propiedad , que especifica el proxy que se comunica con servidores remotos en nombre del WebClient objeto .
Producto | Versiones |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: