Search code examples
blazorblazor-webassemblyblazor-client-side

Get Data From external API with Blazor WASM


I try to get data from external API with blazor WASM but i've got exception: "TypeError: NetworkError when attempting to fetch resource" My code is like belowe. Coulde someone tell me what should i do to get this data? Thank you in advance.

    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");

Solution

  • Change your request to https.

    var test = await Http.GetFromJsonAsync<Nbp>("https://api.nbp.pl/api/exchangerates/rates/A/EUR/2020-12-15/?format=json");