1. 程式人生 > >nodejs 解決跨域

nodejs 解決跨域

app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    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();
});

  

“簡單請求”
 請求方法是以下三種方法之一:
HEAD
GET
POST

“非簡單請求”
HTTP的頭資訊不超出以下幾種欄位:
Accept
Accept-Language
Content-Language
Last-Event-ID
Content-Type:
application/x-www-form-urlencoded、 multipart/form-data、text/plain
不滿足這些特徵的請求稱為“非簡單請求”,例如:content-type=applicaiton/json , method = PUT/DELETE...