Skip to content

Instantly share code, notes, and snippets.

@shubhamnikam
Last active February 14, 2021 18:26
Show Gist options
  • Select an option

  • Save shubhamnikam/37d9ff76701fb7162bfc456f764ba1c2 to your computer and use it in GitHub Desktop.

Select an option

Save shubhamnikam/37d9ff76701fb7162bfc456f764ba1c2 to your computer and use it in GitHub Desktop.
GithubController - wrong http call without HttpClientFactory
[HttpGet("TestGithub/{userName}")]
public async Task<IActionResult> TestGithub(string userName)
{
var httpClient = new HttpClient
{
BaseAddress = new Uri("http://api.github.com/"),
DefaultRequestHeaders =
{
{ "Accept", "application/vnd.github.v3+json" },
{ "User-Agent", "HttpClientFactoryExample" }
}
};
var accountInfo = await httpClient.GetStringAsync($"users/{userName}");
return Ok(accountInfo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment