【发布时间】:2021-12-22 04:24:03
【问题描述】:
如何使用HttpClient获取所有请求的状态码
apiCall() {
let header1 = new HttpHeaders();
header1 = header1.append('Content-Type', 'application/json');
header1 = header1.append('Authorization', `Bearer ${this.token}`);
this.http.post("URL",
{
"dataSentHere": "data"
}, {
headers: header1
}).subscribe(data => {
console.log(data);
},
(err: HttpErrorResponse) => {
if (err.status === 403) {
console.log("403 status code caught");
}
}
)
}
如何获取返回202、200等的http请求的状态码
【问题讨论】:
-
这能回答你的问题吗? Get status code http.get response angular2
-
还是如何打印状态码200、201、205等
-
从字面上看,上述帖子的第一个答案显示了如何打印状态码
标签: angular typescript http angular-httpclient