简体   繁体   中英

How to call API in asp.net MVC

I want to create a summary page for Covid-19 cases. I found this API: CORONAVIRUS COVID19 API

var client = new RestClient("https://api.covid19api.com/live/country/south-africa/status/confirmed/date/2020-03-21T13:13:30Z");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

My question is: how I can call/get the methods on this API using ASP.NET MVC?

And please note that I'm a beginner

Thanks

This code would allow you to get the data from the Uri you provided above:

var c = new HttpClient();
var r = await c.GetAsync("https://api.covid19api.com/live/country/south-africa/status/confirmed/date/2020-03-21T13:13:30Z");
var json = await r.Content.ReadAsStringAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM