node.js - 无法从 node.js express 上的 Angular HTTPClient 模块接收正文数据
问题描述
我在 Angular 中有一个前端,在 node.js 中有一个带有 express 的后端。
我在 Angular 中执行 POST 请求,如下所示:
this.userDetails = {
address: {
city: "City"
country: "CH"
number: "8"
road: "Road"
zip: "1020"
},
details: {
2FA: false
email: "test@user.io"
gender: "0"
name: "User"
surname: "Name"
}
}
this.http.post(
environment.paymentHook + '/customercreate',
this.userDetails
).subscribe(
res => resolve(res),
err => resolve(err)
);
像这样在后面接收它:
app.use(express.json());
app.options('/customercreate', cors(corsOptionsDelegate), function (req, res) {
res.end();
});
app.post('/customercreate', cors(corsOptionsDelegate), async (request, response) => {
const body = request.body; // --> this appears empty {} when it should have the this.userDetails content
});
有人知道我的问题是什么吗?
解决方案
推荐阅读
- parameters - 通过名称传递评估变量
- ruby - RVM 不保留 ruby 版本
- json - 使用 bash 和 AWS CLI 解除关联并释放来自所有区域的所有弹性 IP 地址的脚本
- angular - 我该如何解决这个问题?serve 命令需要在 Angular 项目中运行,但找不到项目定义
- python - 模块/包导入期间发生了什么
- javascript - 如何使用用户输入的文本值追加一行动态添加的行?
- reactjs - 渲染后无法刷新所选值
- java - 如何在 Android Studio 的媒体播放器中播放下一首歌曲?
- node.js - 更新 mongodb 中的 json 值
- python - Python索引错误:列表索引超出范围