title: How can we use HttpClient in ASP.Net Core?
body: <p>I'm writing ASP.Net MVC Core 2.2 Web App. I need to get data from another web server with HTTP or HTTPS. How should I do this?</p>
  
  <p>I wrote code using <code>HttpClient</code>.</p>
  
  <p>I have a Controller that gets a message and it works fine but, should I be constructing <code>HttpClient</code>?</p>
  
  <pre><code>[Route("api/[controller]")]
  [ApiController]
  public class MyController : ControllerBase
  {
      private readonly IHostingEnvironment _env;
      private readonly ILogger _logger;
      private readonly IUpdateService _updateService;
  
      public MyController(
          IHostingEnvironment env,
          ILogger&lt;MyController&gt; logger,
          IUpdateService updateService)
      {
          _env = env;
          _logger = logger;
          _updateService = updateService;
      }
  
      // POST api/values
      [HttpPost]
      public async Task&lt;IAsyncResult&gt; Post([FromBody]Update update)
      {
          using (HttpClient Client = new HttpClient())
          {
              HttpResponseMessage result = Client.GetAsync(uri).Result;
              switch (result.StatusCode)
              {
                  case HttpStatusCode.Accepted:
                      return true;
                  case HttpStatusCode.OK:
                      return true;
                  default:
                      return false;
              }
          }
      }
  }
  </code></pre>