HttpResponseMessage.EnsureSuccessStatusCode HttpResponseMessage.EnsureSuccessStatusCode HttpResponseMessage.EnsureSuccessStatusCode HttpResponseMessage.EnsureSuccessStatusCode Method

定义

如果 HTTP 响应的 IsSuccessStatusCode 属性是 false,则引发异常。Throws an exception if the IsSuccessStatusCode property for the HTTP response is false.

public:
 System::Net::Http::HttpResponseMessage ^ EnsureSuccessStatusCode();
public System.Net.Http.HttpResponseMessage EnsureSuccessStatusCode ();
member this.EnsureSuccessStatusCode : unit -> System.Net.Http.HttpResponseMessage
Public Function EnsureSuccessStatusCode () As HttpResponseMessage

返回

如果调用成功,HTTP 则响应消息。The HTTP response message if the call is successful.

异常

HTTP 响应失败。The HTTP response is unsuccessful.

注解

EnsureSuccessStatusCode方法将引发异常,如果 HTTP 响应失败。The EnsureSuccessStatusCode method throws an exception if the HTTP response was unsuccessful. 在.NET Framework 和.NET Core 2.2 和早期版本中,如果Content不是null,此方法还将调用Dispose来释放托管和非托管资源。In .NET Framework and .NET Core 2.2 and earlier versions, if the Content is not null, this method will also call Dispose to free managed and unmanaged resources. 从.NET Core 3.0 开始,内容将不被释放。Starting with .NET Core 3.0, the content will not be disposed.

适用于