Collapse AllExpand All      Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: F# Code: JScript 
HttpWebRequest Class

[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.

Namespace:   System.Net
Assembly:  System.Http (in System.Http.dll)
Public Class HttpWebRequest _
	Inherits WebRequest
public class HttpWebRequest : WebRequest
public ref class HttpWebRequest : public WebRequest
type HttpWebRequest =  
    class
        inherit WebRequest
    end
public class HttpWebRequest extends WebRequest

The HttpWebRequest type exposes the following members.

  NameDescription
Public property AcceptGets or sets the value of the Accept HTTP header.
Public property AddressGets the Uniform Resource Identifier (URI) of the Internet resource that actually responds to the request.
Public property AllowAutoRedirectGets or sets a value that indicates whether the request should follow redirection responses.
Public property AllowWriteStreamBufferingGets or sets a value that indicates whether to buffer the data sent to the Internet resource.
Public property ConnectionGroupNameWhen overridden in a descendant class, gets or sets the name of the connection group for the request. (Inherited from WebRequest.)
Public property ContentLengthGets or sets the Content-length HTTP header. (Overrides WebRequest..::..ContentLength.)
Public property ContentTypeGets or sets the value of the Content-type HTTP header. (Overrides WebRequest..::..ContentType.)
Public property ContinueDelegateGets or sets the delegate method called when an HTTP 100-continue response is received from the Internet resource.
Public property CredentialsGets or sets authentication information for the request.
Public property Static member DefaultMaximumResponseHeadersLengthGets or sets the default for the MaximumResponseHeadersLength property.
Public property ExpectGets or sets the value of the Expect HTTP header.
Public property HaveResponseGets a value that indicates whether a response has been received from an Internet resource.
Public property HeadersSpecifies a collection of the name/value pairs that make up the HTTP headers. (Overrides WebRequest..::..Headers.)
Public property HttpsAuthentCertsGets or sets the array of certificates used to authenticate HTTPS servers.
Public property IfModifiedSinceGets or sets the value of the If-Modified-Since HTTP header.
Public property KeepAliveGets or sets a value that indicates whether to make a persistent connection to the Internet resource.
Public property MaximumAutomaticRedirectionsGets or sets the maximum number of redirects that the request follows.
Public property MaximumResponseHeadersLengthGets or sets the maximum allowed length of the response headers.
Public property MethodGets or sets the method for the request. (Overrides WebRequest..::..Method.)
Public property ProtocolVersionGets or sets the version of HTTP to use for the request.
Public property ProxyGets or sets proxy information for the request. (Overrides WebRequest..::..Proxy.)
Public property ReadWriteTimeoutGets or sets a time-out in milliseconds when writing to or reading from a stream.
Public property RefererGets or sets the value of the Referer HTTP header.
Public property RequestUriGets the original Uniform Resource Identifier (URI) of the request. (Overrides WebRequest..::..RequestUri.)
Public property SendChunkedGets or sets a value that indicates whether to send data in segments to the Internet resource.
Public property TimeoutGets or sets the time-out value in milliseconds for the GetResponse and GetRequestStream methods. (Overrides WebRequest..::..Timeout.)
Public property TransferEncodingGets or sets the value of the Transfer-encoding HTTP header.
Public property UserAgentGets or sets the value of the User-agent HTTP header.
Top
  NameDescription
Public method AddRange(Int32)Adds a byte range header to a request for a specific range from the beginning or end of the requested data.
Public method AddRange(Int32, Int32)Adds a byte range header to the request for a specified range.
Public method AddRange(String, Int32)Adds a Range header to a request for a specific range from the beginning or end of the requested data.
Public method AddRange(String, Int32, Int32)Adds a range header to a request for a specified range.
Public method Dispose()()()()Releases the resources used by the HttpWebRequest. (Inherited from WebRequest.)
Protected method Dispose(Boolean)Releases the unmanaged resources used by the HttpWebRequest and optionally releases the managed resources. (Overrides WebRequest..::..Dispose(Boolean).)
Public method Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method FinalizePerforms clean up operations. (Inherited from WebRequest.)
Public method GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public method GetRequestStreamGets a Stream object to use to write request data. (Overrides WebRequest..::..GetRequestStream()()()().)
Public method GetResponseReturns a response from an Internet resource. (Overrides WebRequest..::..GetResponse()()()().)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method ResetClears values for the HttpWebRequest instance.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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 #ctor 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.

When you want to send data to the resource, the GetRequestStream method returns a Stream object to use to send data.

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.

NoteNote

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.