我的浏览器端js代码:
import axios from 'axios';
var testObject = {
field : 'this is a test field'
}
axios.post('/create', testObject)
.then((res) => {
console.log(res);
});
我的 nodejs 代码:
const express = require('express');
const path = require('path');
const app = express();
//middlewares
app.use(express.urlencoded({extended: false}));
app.use(express.static(path.resolve(__dirname, '../dist')));
app.post('/create', (req, res) => {
console.log(req.body);
res.send('this is the server response');
});
const port = 3000;
app.listen(port, () => {
console.log('server listening on port ' + port);
});
我的节点 js 输出:
server listening on port 3000
{}
我的浏览器控制台输出:
{data: "this is the server response", status: 200, statusText: "OK", headers: {…}, config:
{…}, …}
请看,我正在使用解析器正文中间件,请求工作正常,但由于某种原因服务器无法获得请求正文。
慕神8447489
哔哔one
相关分类