✅ HttpClient Get Page Content
I need a method
RequestHelper.GetContent(string url)
that returns the url's html as string.
I also need a method that can get the page content as binary, so i can download files.15 Replies
this is my code so far. the problem is that the whole app freezes when i call GetContentAsync
As in, it's a UI application and the UI thread freezes? How are you calling the method?
.Result
There's your problemAnything but
await
is blockingYou need to make it async and use await, yeah.
Asynchronous programming - C#
Learn about the C# language-level asynchronous programming model provided by .NET Core.
everything is sync
very sync much wow
do i have to make everything async?
Yes
How can i convert getcontentasync to be sync ?
If it's
async
, you need to await
it
If you await
in a method, it needs to be async
You don'tYou should probably make things async. That said, if you want to make a synchronous call you can use the Send method:
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.send?view=net-7.0
thanks