【发布时间】:2019-02-13 23:42:01
【问题描述】:
在创建默认 Blazor 应用 (V0.5.1) 后,我们会得到一个 FetchData.cshtml 页面,该页面从本地 .json 文件中获取其数据
@functions {
WeatherForecast[] forecasts;
protected override async Task OnInitAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF { get; set; }
public string Summary { get; set; }
}
}
这很好用。但是,如果更改此设置以从 .net 核心 rest web api 获取相同的数据,则对 Http.GetJsonAsync 的调用将挂起。没有错误,只是永远不会完成。
protected override async Task OnInitAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>(
"http://localhost:5000/api/weatherforecast/");
}
我错过了什么?
【问题讨论】:
-
弗洛雷斯让我找对了地方。
-
还有一个错误,我只需要添加一个异常处理程序。