public EnsureSuccessStatusCode ( ) : |
||
return |
var client = new HttpClient(); var response = await client.GetAsync("https://myapi.com"); response.EnsureSuccessStatusCode();
var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, "https://myapi.com"); request.Content = new StringContent("some data"); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode();In this example, an HTTP POST request is sent to `https://myapi.com` with some data in the request body. The response is checked to ensure it is successful. If the response is not successful, an exception is thrown. The `EnsureSuccessStatusCode()` method is part of the `System.Net.Http` package library in C#.