I\'m trying to send files to my server with a post request, but when it sends it causes the error:
Request header field Content-Type is not allowed by
this is backend problem. if use sails api on backend change cors.js and add your filed here
module.exports.cors = {
allRoutes: true,
origin: '*',
credentials: true,
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'Origin, X-Requested-With, Content-Type, Accept, Engaged-Auth-Token'
};
Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers
error
means that Access-Control-Allow-Origin
field of HTTP header is not handled or allowed by response. Remove Access-Control-Allow-Origin
field from the request header.
If you are using localhost
and PHP set to this to solve the issue:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
From your front-end use:
{headers: {"Content-Type": "application/json"}}
and boom no more issues from localhost
!