[英]How to call API in asp.net MVC
I want to create a summary page for Covid-19 cases.我想为 Covid-19 案例创建一个摘要页面。 I found this API: CORONAVIRUS COVID19 API
我发现了这个 API: 冠状病毒 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?我的问题是:如何使用 ASP.NET MVC 在此 API 上调用/获取方法?
And please note that I'm a beginner请注意我是初学者
Thanks谢谢
This code would allow you to get the data from the Uri you provided above:此代码将允许您从上面提供的 Uri 中获取数据:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.