Created
December 9, 2016 14:55
-
-
Save JoanM/e2bcd5de97b46b60a0f2bfa0e3e445c3 to your computer and use it in GitHub Desktop.
Async Curl to Bynder
This file contains hidden or 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
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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