How to make an HTTP request in C#?
Greetings colleagues!
I've encountered what seems like a trivial task — making an HTTP request to an external API from a .NET 6 console application. I've read several tutorials, but the examples are scattered everywhere: some use
I tried writing a simple GET request using
I run it in the
I've encountered what seems like a trivial task — making an HTTP request to an external API from a .NET 6 console application. I've read several tutorials, but the examples are scattered everywhere: some use
HttpClient, others use WebClient (deprecated?), and some use RestSharp. I want to understand the modern and correct approach.I tried writing a simple GET request using
HttpClient, but the application hangs. Here's the code:var client = new HttpClient();\nvar response = await client.GetAsync("https://api.github.com/zen");\nvar content = await response.Content.ReadAsStringAsync();\nConsole.WriteLine(content);I run it in the
Main method (without async), and I get a warning that the async No answers yet.
Log in to leave an answer
Blogs