我有 2 个 POST 正在通过 Promise 运行,但无论哪一个在内部,它们都会捕获而不执行内部 POST。
我有以下代码:
this.http.post(medurl, datamed)
.toPromise()
.then(response => {
console.log('Post Success!');
console.log('Reponse: ' + response);
if (response != 0){
this.http.post(scripturl, datascript)
.toPromise()
.then(response => {
console.log('Post Success!');
console.log('Reponse: ' + response);
})
.catch(error => {
console.log('Post Error!');
console.log('Reponse: ' + typeof(error));
});
}
})
.catch(error => {
console.log('Post Error!');
console.log('Reponse: ' + typeof(error));
});
我不确定问题是什么,因为我已经对 POST 字段进行了两次三重检查,它们在不同的上下文中工作得很好,而且响应是 200。
我不确定要在此处添加哪些其他详细信息,但如果您需要更多信息,请告诉我。
最佳答案
我遇到了类似的问题,我收到了 200 状态响应,但仍然会抛出错误。我必须在 HttpClient
的 post 方法的 options
参数上设置 responseType
属性。
this.http.post(medurl, datamed, { responseType: 'text' })
.toPromise()
.then(response => {
....
})
.catch(error => {
console.log('Post Error!');
console.log('Reponse: ' + typeof(error));
});
关于angular - 在 Angular 4 中使用 POST 时获得 200 状态但仍然出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54964150/