HttpResponseMessage HttpResponseMessage HttpResponseMessage Class

Definition

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

public sealed class HttpResponseMessage : IClosable, IStringable, IHttpResponseMessagepublic sealed class HttpResponseMessage : IDisposable, IStringable, IHttpResponseMessagePublic NotInheritable Class HttpResponseMessage Implements IDisposable, IStringable, IHttpResponseMessage
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

A common way to get an HttpResponseMessage is the from the return value for one of the DeleteAsync, GetAsync, PostAsync , PutAsync, or SendRequestAsync methods on the HttpClient object.

Constructors

HttpResponseMessage() HttpResponseMessage() HttpResponseMessage()

Initializes a new instance of the HttpResponseMessage class.

public HttpResponseMessage()public HttpResponseMessage()Public Sub New()
Attributes

HttpResponseMessage(HttpStatusCode) HttpResponseMessage(HttpStatusCode) HttpResponseMessage(HttpStatusCode)

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

public HttpResponseMessage(HttpStatusCode statusCode)public HttpResponseMessage(HttpStatusCode statusCode)Public Sub New(statusCode As HttpStatusCode)
Parameters
statusCode
HttpStatusCode HttpStatusCode HttpStatusCode

The status code of the HTTP response.

Attributes

Properties

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

The content of the HTTP response message on the HttpResponseMessage object.

Attributes

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

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
Attributes

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

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

Attributes

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

The reason phrase sent by the server.

Attributes

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

The request message which led to this response message.

Attributes

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

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
Attributes

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

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

The status code of the HTTP response.

Attributes

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

The HTTP protocol version. The default is 1.1.

Attributes

Methods

Close() Close() Close()

Closes the HttpResponseMessage 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 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.

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

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

The HTTP response if the request was successful.

Attributes

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

Returns a string that represents the current HttpResponseMessage object.

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

A string that represents the current object.

Attributes