我试图用blazor WASM从外部API获取数据,但我得到了一个异常:";TypeError:NetworkError when attempting 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");