Mono Class Library: System.Net Namespace

System.Net.HttpWebRequest Class

Provides an HTTP-specific implementation of the System.Net.WebRequest class. [Edit]

See Also: HttpWebRequest Members

System.Object
     System.MarshalByRefObject
          System.Net.WebRequest
               System.Net.HttpWebRequest

public class HttpWebRequest : WebRequest

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

This class implements properties and methods defined in System.Net.WebRequest and provides additional properties and methods that enable the user to interact directly with servers using the Hypertext Transfer Protocol (HTTP).

Note:

Instances of this class are automatically created by the System.Net.WebRequest class. For example, an instance of System.Net.HttpWebRequest is created when the WebRequest.Create(Uri, bool) method is called and a Uniform Resource Identifier (URI) beginning with http:// is specified. It is expected that an instance of this class will be constructed for every request made to the server. For example, after a call to HttpWebRequest.Abort cancels an asynchronous operation, a call to HttpWebRequest.GetRequestStream causes a System.Net.WebException to be thrown.

Requests can be sent synchronously or asynchronously. The HttpWebRequest.GetResponse method sends a request to a server synchronously and returns a System.Net.HttpWebResponse instance containing the response. An asynchronous request for a resource is sent using the HttpWebRequest.BeginGetResponse(AsyncCallback, object) and HttpWebRequest.EndGetResponse(IAsyncResult) methods.

Request data is sent using a request stream. The HttpWebRequest.GetRequestStream , HttpWebRequest.BeginGetRequestStream(AsyncCallback, object), and HttpWebRequest.EndGetRequestStream(IAsyncResult) methods return a System.IO.Stream instance used to send data.

When errors occur while accessing an Internet resource, the System.Net.HttpWebRequest class throws a System.Net.WebException , and the WebException.Status property that indicates the source of the error. When WebException.Status is WebExceptionStatus.ProtocolError, the WebException.Response property contains the System.Net.HttpWebResponse received from the Internet resource.

Certain HTTP headers are protected; the user cannot set them directly in the header collection obtained from the HttpWebRequest.Headers property. Instead, these headers are set using the associated properties of a System.Net.HttpWebRequest instance, or are set by the system. The following table describes how each protected header is set.

HeaderSet by
AcceptHttpWebRequest.Accept
Connection

HttpWebRequest.Connection

HttpWebRequest.KeepAlive

Content-LengthHttpWebRequest.ContentLength
Content-TypeHttpWebRequest.ContentType
ExpectHttpWebRequest.Expect
DateSet to current date by the system.
Host Set to current host by the system.
if-Modified-sinceHttpWebRequest.IfModifiedSince
RangeHttpWebRequest.AddRange(int, int)
RefererHttpWebRequest.Referer
Transfer-Encoding

HttpWebRequest.TransferEncoding

HttpWebRequest.SendChunked

User-AgentHttpWebRequest.UserAgent
[Edit]

Requirements

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