HttpResponseMessage
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// You can use this class in JavaScript.
- Attributes
| 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() HttpResponseMessage()
Initializes a new instance of the HttpResponseMessage class.
public : HttpResponseMessage()public HttpResponseMessage()Public Sub New()// You can use this method in JavaScript.
- See Also
HttpResponseMessage(HttpStatusCode) 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)// You can use this method in JavaScript.
- statusCode
- HttpStatusCode HttpStatusCode HttpStatusCode HttpStatusCode
The status code of the HTTP response.
- See Also
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// You can use this property in JavaScript.
The content of the HTTP response message on the HttpResponseMessage object.
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.
- IHttpContent - a base interface representing an HTTP entity body and content headers.
- HttpBufferContent - HTTP content based on a stream.
- HttpFormUrlEncodedContent - HTTP content based on name/value data encoded using application/x-www-form-urlencoded MIME type.
- HttpStreamContent - HTTP content based on a stream.
- HttpStringContent - HTTP content based on a string.
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// You can use this property in JavaScript.
- Value
- HttpResponseHeaderCollection HttpResponseHeaderCollection HttpResponseHeaderCollection HttpResponseHeaderCollection
The collection of HTTP response headers.
Remarks
The Headers property returns an HttpResponseHeaderCollection object that can be used to get or set the specific headers on the HTTP response.
- See Also
IsSuccessStatusCode IsSuccessStatusCode IsSuccessStatusCode IsSuccessStatusCode
Gets a value that indicates whether the HTTP response was successful.
public : PlatForm::Boolean IsSuccessStatusCode { get; }public bool IsSuccessStatusCode { get; }Public ReadOnly Property IsSuccessStatusCode As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean 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.
- See Also
ReasonPhrase ReasonPhrase ReasonPhrase ReasonPhrase
Gets or sets the reason phrase which typically is sent by servers together with the status code.
public : PlatForm::String ReasonPhrase { get; set; }public string ReasonPhrase { get; set; }Public ReadWrite Property ReasonPhrase As string// You can use this property in JavaScript.
- Value
- PlatForm::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// You can use this property in JavaScript.
The request message which led to this response message.
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// You can use this property in JavaScript.
- Value
- HttpResponseMessageSource HttpResponseMessageSource HttpResponseMessageSource HttpResponseMessageSource
The source of the data received in the HttpResponseMessage.
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// You can use this property in JavaScript.
The status code of the HTTP response.
- See Also
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// You can use this property in JavaScript.
The HTTP protocol version. The default is 1.1.
- See Also
Methods
Close() 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// You can use this method in JavaScript.
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() Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()
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// You can use this method in JavaScript.
The HTTP response if the request was successful.
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.
- See Also
ToString() ToString() ToString() ToString()
Returns a string that represents the current HttpResponseMessage object.
public : PlatForm::String ToString()public string ToString()Public Function ToString() As string// You can use this method in JavaScript.
A string that represents the current object.