I have a C# Backend+API that I interact with from my Vue Application using axios to make requests. In the C# code, there is an endpoint that looks like this:
// GET: api/Timezone
public HttpResponseMessage GetTimezoneData()
{
var timezones = _service.GetSmcTimezones();
var osTimezones = _service.GetOSTimezones();
var resp = JsonConvert.SerializeObject(osTimezones);
//new JsonResult { Data = osTimezones, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
return response;
}
In the frontend, I access this request using the following code:
const config:AxiosRequestConfig = {
method: 'get',
url: 'https://localhost:44333/api/Timezone/',
headers: { }
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
}
}
What's strange is that I can successfully retrieve data using Postman, but when sending the request from the frontend, it fails. I receive a (failed)net::ERR_FAILED error code and no response data. Does anyone have any insights on this issue?