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 ?