GlobalProxySelection.Select Свойство

Определение

Возвращает или устанавливает глобальный прокси-сервер HTTP.

public:
 static property System::Net::IWebProxy ^ Select { System::Net::IWebProxy ^ get(); void set(System::Net::IWebProxy ^ value); };
public static System.Net.IWebProxy Select { get; set; }
member this.Select : System.Net.IWebProxy with get, set
Public Shared Property Select As IWebProxy

Значение свойства

IWebProxy

Объект IWebProxy, используемый всеми вызовами GetResponse().

Исключения

Для операции задания было указано значение null.

Вызывающий объект не имеет разрешения на запрошенную операцию.

Примеры

В следующем примере кода свойство задается Select пустым прокси-сервером.

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

Комментарии

Свойство Select задает прокси-сервер, используемый всеми WebRequest экземплярами, если запрос поддерживает прокси-серверы, а прокси-сервер явно не задается с помощью Proxy свойства. Прокси-серверы в настоящее время поддерживаются FtpWebRequest и HttpWebRequest.

Применяется к