我正在尝试使用express编写一些客户端-服务器程序。但是无论我尝试什么req.body总是空的。我已经在寻找解决方案,但是在大多数情况下,主要的问题是'Content-Type'或app.use(bodyParser.json());缺失。我都拥有,但仍然无法正常工作。
这是我的服务器端:
Exception has occurred: AttributeError
module 'sys' has no attribute '__breakpointhook__'
File "/home/rick/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/testlauncher.py", line 58, in run
pass
File "/home/rick/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/testlauncher.py", line 64, in <module>
run(cwd, testRunner, args)
这是客户端:
const express = require('express');
const app = express();
const port = 5000;
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.post('/', (req, res) => {
console.log(req.body);
res.send(req.body);
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
答案 0 :(得分:1)
问题在于模式:“不匹配” 。您将无法设置Accept和Context-Type标头。