Table of Contents

Class HttpResponseMessage

Namespace
System.Net.Http
Assembly
System.Net.Http.dll

Represents a HTTP response message including the status code and data.

public class HttpResponseMessage : IDisposable
Inheritance
HttpResponseMessage
Implements
Inherited Members
Extension Methods

Constructors

HttpResponseMessage()

Initializes a new instance of the HttpResponseMessage class.

public HttpResponseMessage()

HttpResponseMessage(HttpStatusCode)

Initializes a new instance of the HttpResponseMessage class.

public HttpResponseMessage(HttpStatusCode statusCode)

Parameters

statusCode HttpStatusCode

The status code of the HTTP response.

Exceptions

ArgumentOutOfRangeException

If statusCode has an invalid value.

Properties

Content

Gets or sets the content of a HTTP response message.

public HttpContent Content { get; set; }

Property Value

HttpContent

The content of the HTTP response message.

Headers

Gets the collection of HTTP response headers.

public HttpResponseHeaders Headers { get; }

Property Value

HttpResponseHeaders

The collection of HTTP response headers.

IsSuccessStatusCode

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

public bool IsSuccessStatusCode { get; }

Property Value

bool

true if StatusCode was in the range 200-299; otherwise, false.

ReasonPhrase

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

public string ReasonPhrase { get; set; }

Property Value

string

The reason phrase sent by the server.

RequestMessage

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

public HttpRequestMessage RequestMessage { get; set; }

Property Value

HttpRequestMessage

The request message which led to this response message.

Remarks

This property is set to the request message which led to this response message. In the case of 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 URL actually created the response (useful in case of redirects).

StatusCode

Gets or sets the status code of the HTTP response.

public HttpStatusCode StatusCode { get; }

Property Value

HttpStatusCode

The status code of the HTTP response.

Version

Gets or sets the HTTP message version.

public Version Version { get; set; }

Property Value

Version

The HTTP message version. The default is 1.1.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

EnsureSuccessStatusCode()

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

public HttpResponseMessage EnsureSuccessStatusCode()

Returns

HttpResponseMessage

The HTTP response message if the call is successful.

Exceptions

HttpRequestException