Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor WebAssembly how to fix 'TypeError: Failed to fetch'

$
0
0

I'm trying to call an API in Blazor WebAssembly like this:

public async Task<string?> MakeReservation(MakeReservationModel model){    string result = "";    try    {        var _httpClient = new HttpClient();        var jsonRequest = JsonConvert.SerializeObject(model);        var jsoncontent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");        var response = await _httpClient.PostAsync("xyz/api/pianeta/zyx", jsoncontent);        if (response.StatusCode == HttpStatusCode.OK)        {            result = await response.Content.ReadAsStringAsync();        }        return result;    }    catch (Exception ex)    {        throw;    }}

but I'm getting this error:

'TypeError: Failed to fetch'

How can I fix this ?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>