blazor - 使用 Blazor WASM 从外部 API 获取数据
问题描述
我尝试使用 blazor WASM 从外部 API 获取数据,但出现异常:“TypeError: NetworkError when trying to fetch resource” 我的代码如下所示。有人能告诉我我应该怎么做才能得到这些数据吗?先感谢您。
public class Rate
{
public string no { get; set; }
public string effectiveDate { get; set; }
public double mid { get; set; }
}
public class Nbp
{
public string table { get; set; }
public string currency { get; set; }
public string code { get; set; }
public Rate[] rates { get; set; }
}
//...
var test = await Http.GetFromJsonAsync<Nbp>("http://api.nbp.pl/api/exchangerates/rates/A/EUR/2020-12-15/?format=json");
解决方案
将您的请求更改为https
.
var test = await Http.GetFromJsonAsync<Nbp>("https://api.nbp.pl/api/exchangerates/rates/A/EUR/2020-12-15/?format=json");
推荐阅读
- javascript - Vue:如何根据所选选项更改路线,并在
- json - package.json 知道是否有任何未使用的依赖项
- parallel-processing - 了解如何在 Slurm 上提交并行计算作业
- r - 增加三元图中的箭头粗细 [ggtern]
- wpf - 绑定命令到加载的视图模型
- python-3.x - 如何在太平洋时区使用 Google Calendar API 提取我今天拥有的所有事件
- postgresql - postgres查询不同的表
- php - 通过 ODBC 将 codeigniter 3 连接到任何地方的 SQL
- python - discord.py 给自定义状态排名
- list - 我的递归函数总是返回 None