Export (0) Print
Expand All

GlobalProxySelection.Select Property

Gets or sets the global HTTP proxy.

Namespace: System.Net
Assembly: System (in system.dll)

public static IWebProxy Select { get; set; }
/** @property */
public static IWebProxy get_Select ()

/** @property */
public static void set_Select (IWebProxy value)

public static function get Select () : IWebProxy

public static function set Select (value : IWebProxy)

Not applicable.

Property Value

An IWebProxy that every call to HttpWebRequest.GetResponse uses.

Exception typeCondition

ArgumentNullException

The value specified for a set operation was a null reference (Nothing in Visual Basic).

SecurityException

The caller does not have permission for the requested operation.

The Select property sets the proxy that all WebRequest instances use if the request supports proxies and no proxy is set explicitly using the Proxy property. Proxies are currently supported by FtpWebRequest and HttpWebRequest.

The following code example sets the Select property to the empty 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();
        }
    }
}

package Examples.Http;

import System.*;
import System.Net.*;
import System.IO.*;

public class TestGlobalProxySelection
{
    public static void main(String[] args)
    {
        // Create a request for the Web page at www.contoso.com.
        WebRequest request = WebRequest.Create("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();
        GlobalProxySelection.set_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();
    } //main
} //TestGlobalProxySelection

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft