node报错Request header field Content-Type is not allowed by

When I cross-domain request a post in the front console error Request header field Content-Type is not allowed by Access-Control-Allow-Header. This is because when I set up cross-domain request type of request is not required in the back-end, as shown:
 
app.all('*', function (req, res, next) {
  // header specifies whether the resource in response to the response are allowed to share with a given origin. * Represents all domains are accessible, and can be specified instead of the * url, it means that only the specified url can access to resources 
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers",  "X-Requested-With");
    // a manner that allows the requested resource
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
  });
 
Therefore what is provided directly from the code fragment:
 
app.all('*', function (req, res, next) {
  // header specifies whether the resource in response to the response are allowed to share with a given origin. * Represents all domains are accessible, and can be specified instead of the * url, it means that only the specified url can access to resources 
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers",  " Origin, X-Requested-With, Content-Type, Accept");
    // a manner that allows the requested resource
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
  });
 

Guess you like

Origin www.cnblogs.com/ydam/p/10983576.html