Skip to content

Instantly share code, notes, and snippets.

@JoanM
Created December 9, 2016 14:55
Show Gist options
  • Save JoanM/e2bcd5de97b46b60a0f2bfa0e3e445c3 to your computer and use it in GitHub Desktop.
Save JoanM/e2bcd5de97b46b60a0f2bfa0e3e445c3 to your computer and use it in GitHub Desktop.
Async Curl to Bynder
public async Task<string> DoCurlAsync()
{
using (var httpClient = new HttpClient())
using (var httpResonse = await httpClient.GetAsync("https://www.bynder.com"))
{
return await httpResonse.Content.ReadAsStringAsync();
}
}
@MikeVelso
Copy link

Your code does not work @JoanM.
httpClient on line 4 can't be used because it is out of scope.
Secondly, even if it is in the same scope you don't create and dispose HttpClient on each call.
See https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client#create-and-initialize-httpclient

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