json - POST时HttpClient没有得到响应
问题描述
我想从服务器接收响应。使用 Postman 效果很好: 请求:
{
"name": "antonio",
"username": "antonio",
"email": "antonio@antonio.pl",
"password": "antonio"
}
回复:
{
"success": true,
"message": "User was successfully registered"
}
我试图在 Angular 中实现同样的东西,所以我得到了:
this.http.post('http://localhost:8090/api/auth/signup',
JSON.stringify({name: name, username: username, password: password, email: email}),
{headers: new HttpHeaders({'Content-Type': 'application/json'})})
.subscribe(res => alert(res[0]));
检查后端 API,效果很好,但仍然没有出现警报。有任何想法吗?
解决方案
如果您将请求作为“应用程序/json”发送,则不需要 JSON.stringify() 请求。我不知道您的后端如何解释它。
this.http.post('http://localhost:8090/api/auth/signup',
{name: name, username: username, password: password, email: email},
{headers: new HttpHeaders({'Content-Type': 'application/json'})})
.subscribe(res => alert(res[0]));
推荐阅读
- python - 字符串包含两个数字之一
- reactjs - 转到 Visual Studio 代码中的定义不适用于组件的 Package.json
- c++ - 让虚方法接受任何 Qt 容器类型作为输入参数
- aws-lambda - AWS 代理:在 lambda 中使用 sequelize 时 RDS 连接限制
- excel - VBA:if Then循环中的语句失败
- r - R 中的矢量回收概念
- qt - QT creator 4.7.4 VS QT creator 4.15.0:菜单图标的大小
- syntax - 在 Ocaml 中找到 **,但不是求幂
- c# - 在 mds 中使用 ValidationProcessAsync 验证创建的实体的问题
- html - HTML 和 CSS 中的标签和单选按钮