HttpRequestMessage HttpRequestMessage HttpRequestMessage HttpRequestMessage Class

Represents an HTTP request message including headers.

Syntax

Declaration

public sealed class HttpRequestMessagepublic sealed class HttpRequestMessagePublic NotInheritable Class HttpRequestMessage

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 @Windows.Web.Http.HttpClient.#ctor 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 SendRequestAsync(Windows.Web.Http.HttpRequestMessage,Windows.Web.Http.HttpCompletionOption) 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 summary

Initializes a new instance of the HttpRequestMessage class.

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

Properties summary

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

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

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

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

Gets or sets the Uri used for the HttpRequestMessage object.

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

Methods summary

Closes the HttpRequestMessage instance and releases allocated resources.

Returns a string that represents the current HttpRequestMessage object.

Constructors

  • HttpRequestMessage()
    HttpRequestMessage()
    HttpRequestMessage()
    HttpRequestMessage()

    Initializes a new instance of the HttpRequestMessage class.

    public HttpRequestMessage()public HttpRequestMessage()Public Function HttpRequestMessage() As
  • HttpRequestMessage(Windows.Web.Http.HttpMethod,Windows.Foundation.Uri)
    HttpRequestMessage(Windows.Web.Http.HttpMethod,Windows.Foundation.Uri)
    HttpRequestMessage(Windows.Web.Http.HttpMethod,Windows.Foundation.Uri)
    HttpRequestMessage(Windows.Web.Http.HttpMethod,Windows.Foundation.Uri)

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

    public HttpRequestMessage(Windows.Web.Http.HttpMethod method,Windows.Foundation.Uri uri)public HttpRequestMessage(Windows.Web.Http.HttpMethod method,Windows.Foundation.Uri uri)Public Function HttpRequestMessage(method As Windows.Web.Http.HttpMethod,uri As Windows.Foundation.Uri) As

    Parameters

Properties

Methods

  • Close()
    Close()
    Close()
    Close()

    Closes the HttpRequestMessage instance and releases allocated resources.

    public void Close()public void Close()Public Function Close() As void

    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.

  • ToString()
    ToString()
    ToString()
    ToString()

    Returns a string that represents the current HttpRequestMessage object.

    public string ToString()public string ToString()Public Function ToString() As string

    Returns

    • string
      string
      string
      string

      A string that represents the current object.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Web.Http.dll