【发布时间】:2019-10-27 20:40:41
【问题描述】:
我尝试向 API 发出 http post 请求。 问题如下:API 返回 200 状态码,即成功请求。但在我的代码中,就像在 http 中一样,出现了错误。
我的服务代码:
getUsers(data) {
const httpOptions = {
headers: new HttpHeaders({
"Accept": "application/json"
})
};
let input = new FormData();
input.append('firstName', data.firstName);
return this.http.post('http://localhost/post.php', input, httpOptions);
}
我的组件代码:
callApi(data) {
this.userService.getUsers(data)
.subscribe(
(data) => { // Success
console.log(data)
},
(error) => {
console.error("Error: " + JSON.stringify(error));
}
);
}
可能是什么问题?
【问题讨论】:
-
你能把你在 JSON.stringify(error) 中看到的东西贴出来吗;
-
@Sajeetharan 我更新了帖子。截图在这里:i.stack.imgur.com/M3UPH.png