使用HttpClient呼叫API

  • 150
  • 0

使用System.Net.Http.HttpClient擴充去呼叫API

using System.Net.Http;

HttpClient Client = new HttpClient();    

var response = Client.GetStringAsync(API URL).Result;

 

參考:

https://blog.kkbruce.net/2012/05/aspnet-web-api-8-http-http-message.html#.XQ-TTS8W5QI

https://blog.kkbruce.net/2012/05/aspnet-web-api-9-systemnethttphttpclien.html#.XQ-TTy8W5QI