/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/networking/snippets/httpclient/Program.Put.cs
37 строк
1012 B
David Pine
Replace Host creation, and fix #34867 (#35413)
22 май 2023, 20:07
Не верифицирован
22 май 2023, 20:07
c520d5b
Код
Авторство
О чём код?
static partial class Program { // <put> static async Task PutAsync(HttpClient httpClient) { using StringContent jsonContent = new( JsonSerializer.Serialize(new { userId = 1, id = 1, title = "foo bar", completed = false }), Encoding.UTF8, "application/json"); using HttpResponseMessage response = await httpClient.PutAsync( "todos/1", jsonContent); response.EnsureSuccessStatusCode() .WriteRequestToConsole(); var jsonResponse = await response.Content.ReadAsStringAsync(); Console.WriteLine($"{jsonResponse}\n"); // Expected output: // PUT https://jsonplaceholder.typicode.com/todos/1 HTTP/1.1 // { // "userId": 1, // "id": 1, // "title": "foo bar", // "completed": false // } } // </put> }