HttpResponseMessage HttpResponseMessage HttpResponseMessage HttpResponseMessage Class

Represents an HTTP response message including headers, the status code, and data.

Syntax

Declaration

public sealed class HttpResponseMessagepublic sealed class HttpResponseMessagePublic NotInheritable Class HttpResponseMessage

Remarks

A common way to get an HttpResponseMessage is the from the return value for one of the DeleteAsync(Windows.Foundation.Uri), GetAsync(Windows.Foundation.Uri,Windows.Web.Http.HttpCompletionOption), PostAsync(Windows.Foundation.Uri,Windows.Web.Http.IHttpContent) , PutAsync(Windows.Foundation.Uri,Windows.Web.Http.IHttpContent), or SendRequestAsync(Windows.Web.Http.HttpRequestMessage,Windows.Web.Http.HttpCompletionOption) methods on the HttpClient object.

Constructors summary

Initializes a new instance of the HttpResponseMessage class.

Initializes a new instance of the HttpResponseMessage class with a specific HttpStatusCode.

Properties summary

Gets or sets the content of the HTTP response message on the HttpResponseMessage object.

Gets the collection of HTTP response headers associated with the HttpResponseMessage that were sent by the server.

Gets a value that indicates whether the HTTP response was successful.

Gets or sets the reason phrase which typically is sent by servers together with the status code.

Gets or sets the request message which led to this response message.

Gets the source of the data received in the HttpResponseMessage.

Gets or sets the status code of the HTTP response.

Gets or sets the HTTP protocol version used on the HttpResponseMessage object.

Methods summary

Closes the HttpResponseMessage instance and releases allocated resources.

Throws an exception if the IsSuccessStatusCode property for the HTTP response is false.

Returns a string that represents the current HttpResponseMessage object.

Constructors

  • HttpResponseMessage()
    HttpResponseMessage()
    HttpResponseMessage()
    HttpResponseMessage()

    Initializes a new instance of the HttpResponseMessage class.

    public HttpResponseMessage()public HttpResponseMessage()Public Function HttpResponseMessage() As
  • HttpResponseMessage(Windows.Web.Http.HttpStatusCode)
    HttpResponseMessage(Windows.Web.Http.HttpStatusCode)
    HttpResponseMessage(Windows.Web.Http.HttpStatusCode)
    HttpResponseMessage(Windows.Web.Http.HttpStatusCode)

    Initializes a new instance of the HttpResponseMessage class with a specific HttpStatusCode.

    public HttpResponseMessage(Windows.Web.Http.HttpStatusCode)public HttpResponseMessage(Windows.Web.Http.HttpStatusCode)Public Function HttpResponseMessage(Windows.Web.Http.HttpStatusCode) As

    Parameters

Properties

  • Content
    Content
    Content
    Content

    Gets or sets the content of the HTTP response message on the HttpResponseMessage object.

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

    Property Value

    Remarks

    The content of an HTTP response 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.

  • Headers
    Headers
    Headers
    Headers

    Gets the collection of HTTP response headers associated with the HttpResponseMessage that were sent by the server.

    public HttpResponseHeaderCollection Headers { get; }public HttpResponseHeaderCollection Headers { get; }Public ReadOnly Property Headers As HttpResponseHeaderCollection

    Property Value

    Remarks

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

  • IsSuccessStatusCode
    IsSuccessStatusCode
    IsSuccessStatusCode
    IsSuccessStatusCode

    Gets a value that indicates whether the HTTP response was successful.

    public bool IsSuccessStatusCode { get; }public bool IsSuccessStatusCode { get; }Public ReadOnly Property IsSuccessStatusCode As bool

    Property Value

    • bool
      bool
      bool
      bool

      A value that indicates if the HTTP response was successful. true if HttpStatusCode was in the Successful range (200-299); otherwise false.

  • ReasonPhrase
    ReasonPhrase
    ReasonPhrase
    ReasonPhrase

    Gets or sets the reason phrase which typically is sent by servers together with the status code.

    public string ReasonPhrase { get; set; }public string ReasonPhrase { get; set; }Public ReadWrite Property ReasonPhrase As string

    Property Value

    • string
      string
      string
      string

      The reason phrase sent by the server.

  • RequestMessage
    RequestMessage
    RequestMessage
    RequestMessage

    Gets or sets the request message which led to this response message.

    public HttpRequestMessage RequestMessage { get; set; }public HttpRequestMessage RequestMessage { get; set; }Public ReadWrite Property RequestMessage As HttpRequestMessage

    Property Value

    Remarks

    This property is set to the request message which led to this response message. For a request sent using HttpClient, this property will point to the actual request message leading to the final response. Note that this may not be the same message the user provided when sending the request. This is typically the case if the request needs to be resent due to redirects or authentication. This property can be used to determine what URI actually created the response (useful in case of redirects).

  • Source
    Source
    Source
    Source

    Gets the source of the data received in the HttpResponseMessage.

    public HttpResponseMessageSource Source { get; set; }public HttpResponseMessageSource Source { get; set; }Public ReadWrite Property Source As HttpResponseMessageSource

    Property Value

    Remarks

    The Source property indicates whether the data received in the HttpResponseMessage was from the local cache or was received over the network.

  • StatusCode
    StatusCode
    StatusCode
    StatusCode

    Gets or sets the status code of the HTTP response.

    public HttpStatusCode StatusCode { get; set; }public HttpStatusCode StatusCode { get; set; }Public ReadWrite Property StatusCode As HttpStatusCode

    Property Value

  • Version
    Version
    Version
    Version

    Gets or sets the HTTP protocol version used on the HttpResponseMessage object.

    public HttpVersion Version { get; set; }public HttpVersion Version { get; set; }Public ReadWrite Property Version As HttpVersion

    Property Value

Methods

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

    Closes the HttpResponseMessage 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 HttpResponseMessage instance. The Close() method can manage the lifetime of system resources (memory for the HttpResponseMessage, 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 HttpResponseMessage 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.

  • EnsureSuccessStatusCode()
    EnsureSuccessStatusCode()
    EnsureSuccessStatusCode()
    EnsureSuccessStatusCode()

    Throws an exception if the IsSuccessStatusCode property for the HTTP response is false.

    public HttpResponseMessage EnsureSuccessStatusCode()public HttpResponseMessage EnsureSuccessStatusCode()Public Function EnsureSuccessStatusCode() As HttpResponseMessage

    Returns

    Remarks

    This method will throw an exception if the server doesn't return a successful HttpStatusCode in the Successful range (200-299) for the request.

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

    Returns a string that represents the current HttpResponseMessage 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.ContractVersionAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute

Details

Assembly

Windows.Web.Http.dll