[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Provides an HTTP-specific implementation of the WebRequest class.
<SerializableAttribute> _ Public Class HttpWebRequest _ Inherits WebRequest _ Implements ISerializable
[SerializableAttribute] public class HttpWebRequest : WebRequest, ISerializable
[SerializableAttribute] public ref class HttpWebRequest : public WebRequest, ISerializable
[<SerializableAttribute>] type HttpWebRequest = class inherit WebRequest interface ISerializable end
The HttpWebRequest type exposes the following members.
The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.
Do not use the HttpWebRequest constructor. Use the WebRequest..::.Create method to initialize new HttpWebRequest objects. If the scheme for the Uniform Resource Identifier (URI) is http:// or https://, Create returns an HttpWebRequest object.
The GetResponse method makes a synchronous request to the resource specified in the RequestUri property and returns an HttpWebResponse that contains the response. You can make an asynchronous request to the resource using the BeginGetResponse and EndGetResponse methods.
When you want to send data to the resource, the GetRequestStream method returns a Stream object to use to send data. The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the send data stream.
For client authentication with HttpWebRequest, the client certificate must be installed in the My certificate store of the current user.
The HttpWebRequest class throws a WebException when errors occur while accessing a resource. The WebException..::.Status property contains a WebExceptionStatus value that indicates the source of the error. When WebException..::.Status is WebExceptionStatus..::.ProtocolError, the Response property contains the HttpWebResponse received from the resource.
HttpWebRequest exposes common HTTP header values sent to the Internet resource as properties, set by methods, or set by the system; the following table contains a complete list. You can set other headers in the Headers property as name/value pairs. Note that servers and caches may change or add headers during the request.
The following table lists the HTTP headers that are set either by properties or methods or the system.
Header
Set by
Accept
Set by the Accept property.
Connection
Set by the Connection property, KeepAlive property.
Content-Length
Set by the ContentLength property.
Content-Type
Set by the ContentType property.
Expect
Set by the Expect property.
Date
Set by the system to current date.
Host
Set by the system to current host information.
If-Modified-Since
Set by the IfModifiedSince property.
Range
Set by the AddRange method.
Referer
Set by the Referer property.
Transfer-Encoding
Set by the TransferEncoding property (the SendChunked property must be true).
User-Agent
Set by the UserAgent property.
HttpWebRequest is registered automatically. You do not need to call the RegisterPrefix method to register System.Net..::.HttpWebRequest before using URIs beginning with http:// or https://.
The local computer or application config file may specify that a default proxy be used. If the Proxy property is specified, then the proxy settings from the Proxy property override the local computer or application config file and the HttpWebRequest instance will use the proxy settings specified. If no proxy is specified in a config file and the Proxy property is unspecified, the 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 HttpWebRequest class parses a proxy bypass list with wildcard characters inherited from Internet Explorer differently than the bypass list is parsed directly by Internet Explorer. For example, the HttpWebRequest class will parse a bypass list of "nt*" from Internet Explorer as a regular expression of "nt.$". This differs from the native behavior of Internet Explorer. So a URL of "http://intxxxxx" would bypass the proxy using the HttpWebRequest class, but would not bypass the proxy using Internet Explorer.
The Framework caches SSL sessions as they are created and attempts to reuse a cached session for a new request, if possible. When attempting to reuse an SSL session, the Framework uses the first element of ClientCertificates (if there is one), or tries to reuse an anonymous sessions if ClientCertificates is empty.
For security reasons, cookies are disabled by default. If you want to use cookies, use the CookieContainer property to enable cookies.
The following code example creates an HttpWebRequest for the URI http://www.contoso.com/.
Dim myReq As HttpWebRequest = _ WebRequest.Create("http://www.contoso.com/")
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
HttpWebRequest^ myReq = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.contoso.com/" ));
to access the requested URI or any URI that the request is redirected to. Associated enumeration: Connect
Windows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.