"APIs": {
"API-1": "http://localhost:5000/student",
"API-2": "http://localhost:5001/teacher"}
我在launchSettings.json文件中创建了这些属性。现在我需要访问Student.razor页面中的API-1和API-2值。我试着这样使用它..
List<Student> students = await http.GetFromJsonAsync<List<Student>>("API-1");
发布于 2020-07-04 07:48:58
你不能使用启动设置,你应该使用appsettings.json
在wwwroot中创建一个appsettings.json,并将您的api配置放在其中。
{
"APIs": {
"API-1": "http://localhost:5000/student",
"API-2": "http://localhost:5001/teacher"
}
}
然后在您需要的任何地方使用inject
IConfiguration
。例如:
@inject Microsoft.Extensions.Configuration.IConfiguration config
和
List<Student> students = await http.GetFromJsonAsync<List<Student>>(config["APIs:API-1"]);
https://stackoverflow.com/questions/62721256
复制相似问题