HttpResponseMessage 类

定义

表示 HTTP 响应消息,包括标头、状态代码和数据。

public ref class HttpResponseMessage sealed : IClosable, IStringable
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Web.Http.IHttpResponseMessageFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpResponseMessage final : IClosable, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Web.Http.IHttpResponseMessageFactory, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class HttpResponseMessage final : IClosable, IStringable
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Web.Http.IHttpResponseMessageFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpResponseMessage : System.IDisposable, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Web.Http.IHttpResponseMessageFactory), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class HttpResponseMessage : System.IDisposable, IStringable
function HttpResponseMessage(statusCode)
Public NotInheritable Class HttpResponseMessage
Implements IDisposable, IStringable
继承
Object Platform::Object IInspectable HttpResponseMessage
属性
实现

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

注解

获取 HttpResponseMessage 的常见方法是从 HttpClient 对象上的 DeleteAsyncGetAsyncPostAsyncPutAsyncSendRequestAsync 方法之一的返回值获取 。

构造函数

HttpResponseMessage()

初始化 HttpResponseMessage 类的新实例。

HttpResponseMessage(HttpStatusCode)

使用特定的 HttpStatusCode 初始化 HttpResponseMessage 类的新实例。

属性

Content

获取或设置 HttpResponseMessage 对象上的 HTTP 响应消息的内容。

Headers

获取与服务器发送的 HttpResponseMessage 关联的 HTTP 响应标头的集合。

IsSuccessStatusCode

获取一个值,该值指示 HTTP 响应是否成功。

ReasonPhrase

获取或设置通常由服务器发出的原因短语(与状态代码一起发出)。

RequestMessage

获取或设置导致此响应消息的请求消息。

Source

获取 在 HttpResponseMessage 中接收的数据源。

StatusCode

获取或设置 HTTP 响应的状态代码。

Version

获取或设置 HttpResponseMessage 对象上使用的 HTTP 协议版本。

方法

Close()

关闭 HttpResponseMessage 实例并释放分配的资源。

Dispose()

执行与释放或重置非托管资源关联的应用程序定义的任务。

EnsureSuccessStatusCode()

如果 HTTP 响应对象的 HttpResponseMessage.IsSuccessStatusCode 属性为 false,则引发异常;如果是 true,则不引发异常。

ToString()

返回表示当前 HttpResponseMessage 对象的字符串。

适用于

另请参阅