HttpRequestMessage HttpRequestMessage HttpRequestMessage HttpRequestMessage Class

Represents an HTTP request message including headers.

Syntax

Declaration

public sealed class HttpRequestMessagepublic sealed class HttpRequestMessagePublic NotInheritable Class HttpRequestMessagepublic sealed 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(HttpRequestMessage, 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 New()Public Sub New()public HttpRequestMessage()
  • HttpRequestMessage(HttpMethod, Uri)
    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 New(HttpMethod method, Uri uri)Public Sub New(method As HttpMethod, uri As Uri)public HttpRequestMessage(HttpMethod method, Uri uri)

    Parameters

Properties

  • Content
    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 IHttpContentpublic IHttpContent Content { get; set; }

    Property Value

    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
    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 HttpRequestHeaderCollectionpublic HttpRequestHeaderCollection Headers { get; }

    Property Value

    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
    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 HttpMethodpublic HttpMethod Method { get; set; }

    Property Value

    Remarks

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

  • Properties
    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>public IMap<string, object> Properties { get; }

    Property Value

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

  • RequestUri
    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 Uripublic Uri RequestUri { get; set; }

    Property Value

    Remarks

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

  • TransportInformation
    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 HttpTransportInformationpublic HttpTransportInformation TransportInformation { get; }

    Property Value

    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()
    Close()

    Closes the HttpRequestMessage instance and releases allocated resources.

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

    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 stringpublic string ToString()

    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.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Web.Http.dll