Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers

后端 未结 15 1286
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 16:31

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

相关标签:
15条回答
  • 2020-11-22 16:56

    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'
    };
    
    0 讨论(0)
  • 2020-11-22 16:57

    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.

    0 讨论(0)
  • 2020-11-22 16:57

    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!

    0 讨论(0)
提交回复
热议问题