Reputation: 41
import axios from 'axios';
var data = JSON.stringify({
"email": email,
"password": password
});
var config = {
method: 'post',
url: 'http://localhost:3001/user/Login',
headers: {
'x-api-key': 'apiKey',
'content-type':'application/octet-stream',
'Accept': 'application/json'
},
data : data
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
The Error :
Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:99) Access to XMLHttpRequest at 'http://localhost:3001/user/Login' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
Upvotes: 4
Views: 1722
Reputation: 292
Your url has double forward slash but it should be single forward slas
url: 'http://localhost:3001/user/Login',
This might help !!
Upvotes: 1