Bewerken

Share via


HttpResponseMessage.EnsureSuccessStatusCode Method

Definition

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

Returns

The HTTP response message if the call is successful.

Exceptions

The HTTP response is unsuccessful.

Remarks

The EnsureSuccessStatusCode method throws an exception if the HTTP response was unsuccessful. 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. Starting with .NET Core 3.0, the content will not be disposed.

Applies to