/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/networking/snippets/httpclient/Program.Options.cs
29 строк
880 B
David Pine
Replace Host creation, and fix #34867 (#35413)
22 май 2023, 20:07
Не верифицирован
22 май 2023, 20:07
c520d5b
Код
Авторство
О чём код?
static partial class Program { // <options> static async Task OptionsAsync(HttpClient httpClient) { using HttpRequestMessage request = new( HttpMethod.Options, "https://www.example.com"); using HttpResponseMessage response = await httpClient.SendAsync(request); response.EnsureSuccessStatusCode() .WriteRequestToConsole(); foreach (var header in response.Content.Headers) { Console.WriteLine($"{header.Key}: {string.Join(", ", header.Value)}"); } Console.WriteLine(); // Expected output // OPTIONS https://www.example.com/ HTTP/1.1 // Allow: OPTIONS, GET, HEAD, POST // Content-Type: text/html; charset=utf-8 // Expires: Wed, 17 Aug 2022 17:28:42 GMT // Content-Length: 0 } // </options> }