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

Definition

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
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

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.

Constructors

HttpRequestMessage() HttpRequestMessage() HttpRequestMessage()

Initializes a new instance of the HttpRequestMessage class.

public HttpRequestMessage()public HttpRequestMessage()Public Sub New()
Attributes

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)
Parameters
method
HttpMethod HttpMethod HttpMethod

The HTTP method to perform

uri
Uri Uri Uri

The Uri to request.

Attributes

Properties

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
Value
IHttpContent IHttpContent IHttpContent

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

Attributes

Remarks

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
Value
HttpRequestHeaderCollection HttpRequestHeaderCollection HttpRequestHeaderCollection

The collection of HTTP request headers associated with the HttpRequestMessage.

Attributes

Remarks

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.

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
Value
HttpMethod HttpMethod HttpMethod

The HTTP method to be performed on the request URI.

Attributes

Remarks

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 IMap<string, object> Properties { get; }Public ReadOnly Property Properties As IMap<string, object>
Value

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

Attributes

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
Value
Uri Uri Uri

The Uri used for the HTTP request.

Attributes

Remarks

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
Value
HttpTransportInformation HttpTransportInformation HttpTransportInformation

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

Attributes

Remarks

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.

Methods

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
Attributes

Remarks

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
Attributes

ToString() ToString() ToString()

Returns a string that represents the current HttpRequestMessage object.

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

A string that represents the current object.

Attributes