app.post('*', function (req, res) {
res.writeHead(200, {
"Content-Type": "text/plain",
"Access-Control-Allow-Origin": "http://localhost:63342",
"Access-Control-Allow-Credentials": "true"
});
res.send('haha');
});
app.get('*', function (req, res) {
res.writeHead(200, {
"Set-Cookie": ['name=tom'],
"Content-Type": "text/plain",
"Access-Control-Allow-Origin": "http://localhost:63342",
"Access-Control-Allow-Credentials": "true"
});
fs.readFile('info.txt', function (err, data) {
res.write(data);
res.end();
})
});
为什么用同样的方式(CORS(来做,get方法可以做得很好,但是 发布方法不能,错误:在此处输入图像描述
你试过节点模块 cors 吗?
https://www.npmjs.com/package/cors
app.use(cors());