【发布时间】:2020-04-12 23:45:45
【问题描述】:
HttpErrorResponse 为 200,但“成功”消息从不打印。相反,这会显示在控制台中:
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:5000/api/File/create", ok: false, …}
this.http.post('api/File/create', waldo, { observe: 'response' }).subscribe(data => {
if (data.status == 200) {
console.log("success");
}
});
更新2:
[HttpPost("create")]
public ActionResult<File> Create([FromBody]File file)
{
try
{
_fileService.Create(file);
return Ok("sucess");
}
catch(Exception e)
{
return NotFound();
}
}
【问题讨论】:
-
如果你将第二个回调传递给
subscribe,它会在那里结束吗?您是否有任何可能干扰请求的拦截器? -
@jonrsharpe 不知道该怎么做.. 我刚开始使用 angular 8
-
怎么办?通过回调?你已经通过了第一个,
data => ...。看看例如rxjs-dev.firebaseapp.com/api/index/class/Observable#subscribe 看看你可以通过的各种东西。 -
console.log(data)在if语句之前的控制台上看起来如何? -
@tenkmilan 断点永远不会到达那里...请查看更新