/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/networking/snippets/httpclient/Program.Head.cs
32 строки
926 B
David Pine
Replace Host creation, and fix #34867 (#35413)
22 май 2023, 20:07
Не верифицирован
22 май 2023, 20:07
c520d5b
Код
Авторство
О чём код?
static partial class Program { // <head> static async Task HeadAsync(HttpClient httpClient) { using HttpRequestMessage request = new( HttpMethod.Head, "https://www.example.com"); using HttpResponseMessage response = await httpClient.SendAsync(request); response.EnsureSuccessStatusCode() .WriteRequestToConsole(); foreach (var header in response.Headers) { Console.WriteLine($"{header.Key}: {string.Join(", ", header.Value)}"); } Console.WriteLine(); // Expected output: // HEAD https://www.example.com/ HTTP/1.1 // Accept-Ranges: bytes // Age: 550374 // Cache-Control: max-age=604800 // Date: Wed, 10 Aug 2022 17:24:55 GMT // ETag: "3147526947" // Server: ECS, (cha / 80E2) // X-Cache: HIT } // </head> }