Skip to content

Instantly share code, notes, and snippets.

@drasticactions
Created November 16, 2015 13:10
Show Gist options
  • Save drasticactions/6e58d6d683931994dd26 to your computer and use it in GitHub Desktop.
Save drasticactions/6e58d6d683931994dd26 to your computer and use it in GitHub Desktop.
WebEngine
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();
}
}
}
}
@kiquenet
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment