HttpResponseMessage Class

Represents a response message received from an HTTP server.

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

Syntax

public class HttpResponseMessage : IDisposable

Remarks

The HttpResponseMessage class represents an HTTP response. It contains the status code, headers, and content of the response. This class is typically returned by HttpClient.SendAsync or related methods.

HttpResponseMessage implements IDisposable. It's important to dispose of the HttpResponseMessage object when you are finished with it to release any unmanaged resources.

Constructors

HttpResponseMessage()

Initializes a new instance of the HttpResponseMessage class with a default status code of HttpStatusCode.OK.

HttpResponseMessage(HttpStatusCode statusCode)

Initializes a new instance of the HttpResponseMessage class with a specified HTTP status code.

statusCode: The HTTP status code for the response.

Properties

Content

Gets or sets the HTTP content of the response.

public HttpContent Content { get; set; }

IsSuccessStatusCode

Gets a value indicating whether the HTTP response was successful.

This property is true if the StatusCode property is in the range 200–299 (inclusive); otherwise, it is false.

public bool IsSuccessStatusCode { get; }

ReasonPhrase

Gets or sets the reason phrase that accompanies the HTTP status code returned by the server.

public string ReasonPhrase { get; set; }

RequestMessage

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

public HttpRequestMessage RequestMessage { get; set; }

StatusCode

Gets or sets the HTTP status code for the response.

public HttpStatusCode StatusCode { get; set; }

Version

Gets or sets the HTTP protocol version.

public Version Version { get; set; }

Methods

Dispose()

Releases the unmanaged resources that are used by the object and, optionally, releases the managed resources.

public void Dispose();

EnsureSuccessStatusCode()

Throws an exception if the response indicates an error.

If the IsSuccessStatusCode property is false, this method throws an HttpRequestException.

public HttpResponseMessage EnsureSuccessStatusCode();

See Also