System.Net.HttpWebRequest.Proxy Property

Gets or sets proxy information for the request.

Syntax

public override IWebProxy Proxy { get; set; }

Value

The System.Net.WebProxy instance to use as a proxy for the current instance. The default value is set by calling GlobalProxySelection.Select .

Exceptions

TypeReason
ArgumentNullExceptionA set operation was requested and the specified value was null.
InvalidOperationExceptionA set operation was requested but data has already been sent to the request stream.
System.Security.SecurityExceptionThe caller does not have permission for the requested operation.

Remarks

The HttpWebRequest.Proxy property identifies the System.Net.WebProxy object to use to process requests to Internet resources. To specify that no proxy should be used, set the HttpWebRequest.Proxy property to the proxy instance returned by the GlobalProxySelection.GetEmptyWebProxy method.

The local computer or application config file may specify that a default proxy be used. If the HttpWebRequest.Proxy property is specified, then the proxy settings from the HttpWebRequest.Proxy property override the local computer or application config file and the System.Net.HttpWebRequest instance will use the proxy settings specified. If no proxy is specified in a config file and the HttpWebRequest.Proxy property is unspecified, the System.Net.HttpWebRequest class uses the proxy settings inherited from Internet Explorer on the local computer. If there are no proxy settings in Internet Explorer, the request is sent directly to the server.

The System.Net.HttpWebRequest class parses a proxy bypass list with wildcard characters inherited from Internet Explorer the same as the bypass list is parsed directly by Internet Explorer. For example, the System.Net.HttpWebRequest class will parse a bypass list of "nt*" from Internet Explorer as a regular expression of "nt.*". So a URL of "http://nt.com" would bypass the proxy using the System.Net.HttpWebRequest class and using Internet Explorer.

The System.Net.HttpWebRequest class supports local proxy bypass. The class considers a destination to be local if any of the following conditions are met:

Changing the HttpWebRequest.Proxy property after the request has been started by calling the HttpWebRequest.GetRequestStream, HttpWebRequest.BeginGetRequestStream(AsyncCallback, object), HttpWebRequest.GetResponse, or HttpWebRequest.BeginGetResponse(AsyncCallback, object) method throws an InvalidOperationException. For information on the proxy element see DefaultProxy Element (Network Settings).

Permissions

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0