let url = 'http://localhost:4001/api/v1/sessions/new';
axios.post(url, data)
.then(function(resp) {
console.log('resp returned is ' + JSON.stringify(resp));
});
I see this error in chrome console"
Failed to load http://localhost:4001/api/v1/sessions/new: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4044' is therefore not allowed access. The response had HTTP status code 405.
If I just try and curl the exact same API call it works fine:
curl -d "[email protected]&password=hello123" -X POST http://localhost:4001/api/v1/sessions/new
{"apiResponse":{"success":true,"errors":[]}}
Why does it work with CURL but not with axios?
Anything that isn't running in a browser doesn't care about CORS. If you'd like your web app to make requests to your server add the Access-Control-Allow-Origin header to your server's response with the most permissive value being *:
Access-Control-Allow-Origin: *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With