Http​Request​Message Http​Request​Message Http​Request​Message Class


Represents an HTTP request message including headers.

public : sealed class HttpRequestMessage : IClosable, IStringable, IHttpRequestMessagepublic sealed class HttpRequestMessage : IDisposable, IStringable, IHttpRequestMessagePublic NotInheritable Class HttpRequestMessage Implements IDisposable, IStringable, IHttpRequestMessage
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


The HttpRequestMessage class contains headers, the HTTP verb, and potentially data. This class is commonly used by developers who need additional control over HTTP requests. Common examples include the following:

  • To examine the underlying SSL/TLS transport information.
  • To use a less-common HTTP method.
  • To explicitly set request properties on the HttpRequestMessage.

In these cases, an app uses one of the HttpRequestMessage constructors to create an HttpRequestMessage instance. The app sets various properties on the HttpRequestMessage as needed. Then the HttpRequestMessage is passed as a parameter to one of the HttpClient.SendRequestAsync methods.

A number of convenience methods on the HttpClient class automatically create an HttpRequestMessage object for the app. These methods include the following:

Any filters that you add to the filter pipeline will be passed the HttpRequestMessage object whether it was explicitly specified by the app or was automatically constructed for you.


HttpRequestMessage() HttpRequestMessage() HttpRequestMessage()

HttpRequestMessage(HttpMethod, Uri) HttpRequestMessage(HttpMethod, Uri) HttpRequestMessage(HttpMethod, Uri)

Initializes a new instance of the HttpRequestMessage class with an HTTP method and a request Uri.

public : HttpRequestMessage(HttpMethod method, Uri uri)public HttpRequestMessage(HttpMethod method, Uri uri)Public Sub New(method As HttpMethod, uri As Uri)
HttpMethod HttpMethod HttpMethod

The HTTP method to perform

Uri Uri Uri

The Uri to request.



Content Content Content

Gets or sets the HTTP content to send to the server on the HttpRequestMessage object.

public : IHttpContent Content { get; set; }public IHttpContent Content { get; set; }Public ReadWrite Property Content As IHttpContent
IHttpContent IHttpContent IHttpContent

The HTTP content to send to the server on the HttpRequestMessage object.



The content of an HTTP request message corresponds to the entity body defined in RFC 2616.

A number of classes and an interface can be used for HTTP content. These include the following.

A number of HttpClient methods don't need to set the Content property on the HttpRequestMessage. These include the following:

Headers Headers Headers

Gets the collection of the HTTP request headers associated with the HttpRequestMessage.

public : HttpRequestHeaderCollection Headers { get; }public HttpRequestHeaderCollection Headers { get; }Public ReadOnly Property Headers As HttpRequestHeaderCollection
HttpRequestHeaderCollection HttpRequestHeaderCollection HttpRequestHeaderCollection

The collection of HTTP request headers associated with the HttpRequestMessage.



The Headers property returns an HttpRequestHeaderCollection object that can be used to get or set the specific headers on the HTTP request.

The Headers property represents the headers that an app developer can set, not all of the headers that may eventually be sent with the request. The HttpBaseProtocolFilter will add some additional headers.

See Also

Method Method Method

Gets or sets the HTTP method to be performed on the request URI.

public : HttpMethod Method { get; set; }public HttpMethod Method { get; set; }Public ReadWrite Property Method As HttpMethod
HttpMethod HttpMethod HttpMethod

The HTTP method to be performed on the request URI.



The standard HTTP methods include CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, and TRACE.

Properties Properties Properties

Gets a set of properties on the HttpRequestMessage instance that are for use by the developer.

public : IMap<string, object> Properties { get; }public IDictionary<string, object> Properties { get; }Public ReadOnly Property Properties As IDictionary<string, object>
IMap<PlatForm::String, PlatForm::Object> IDictionary<string, object> IDictionary<string, object>

A set of properties on the HttpRequestMessage instance that are for use by the developer.


RequestUri RequestUri RequestUri

Gets or sets the Uri used for the HttpRequestMessage object.

public : Uri RequestUri { get; set; }public Uri RequestUri { get; set; }Public ReadWrite Property RequestUri As Uri
Uri Uri Uri

The Uri used for the HTTP request.



The value of the RequestUri must not be a relative Uri.

TransportInformation TransportInformation TransportInformation

Get information about the underlying transport socket used by an HTTP connection.

public : HttpTransportInformation TransportInformation { get; }public HttpTransportInformation TransportInformation { get; }Public ReadOnly Property TransportInformation As HttpTransportInformation
HttpTransportInformation HttpTransportInformation HttpTransportInformation

Information about the underlying transport socket used by an HTTP connection.



The primary use of the TransportInformation property is to get SSL information when SSL is used for the HTTP connection. This is commonly used to get the SSL certificate from the server or to view a list of errors that occurred when making an SSL connection.


Close() Close() Close()

Closes the HttpRequestMessage instance and releases allocated resources.

public : void Close()This member is not implemented in C#This member is not implemented in VB.Net


The Close method releases allocated resources used by the HttpRequestMessage instance. The Close method can manage the lifetime of system resources (memory for the HttpRequestMessage, for example) used by a Windows Runtime object.

In the .NET Framework 4.5, this method projects as the Dispose method. In Visual C++ component extensions (C++/CX), this method projects as the destructor (delete operator).

Apps written in JavaScript, C#, or VB.NET use garbage collection to release resources. So the HttpRequestMessage object and associated resources doesn't get released until the garbage collection pass runs. The Close method allows an app to release these resources early rather than waiting for the object to be released by garbage collection.

Apps written in C++ or CX don't have a Close method since these apps can destroy the object. In C++ and CX, objects are released when they fall out of program scope or as part of the destructor (delete operator) for the object.

Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++void Dispose()Sub Dispose

ToString() ToString() ToString()

Returns a string that represents the current HttpRequestMessage object.

public : PlatForm::String ToString()public string ToString()Public Function ToString() As string
PlatForm::String string string

A string that represents the current object.