Created
November 16, 2015 13:10
-
-
Save drasticactions/6e58d6d683931994dd26 to your computer and use it in GitHub Desktop.
WebEngine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Kimono | |
{ | |
public static class KimonoEngine | |
{ | |
public static async Task<string> GetJson(string url) | |
{ | |
using (var httpClient = new HttpClient()) | |
{ | |
var response = await httpClient.GetAsync(url); | |
return await response.Content.ReadAsStringAsync(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wrong usage of the HTTPClient class (in .NET)
In .NET, as Simon Timms described in his article, you have to be careful when using the HTTPClient class.
Continuous instantiation and disposal of the HTTPClient object may create a socket exhaustion on your machine and affect performance.
Consider reusing the HTTPClient object throughout your calls for better performance.
https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
https://ankitvijay.net/2016/09/25/dispose-httpclient-or-have-a-static-instance/