Angular 6 - 订阅中的 HTTP 响应 200 为空

Angular 6 - HTTP Response 200 is null in subscribe

我有以下 Angular http.service.ts 用来调用 /login API.

login(user: User) {
    console.log("logging in");
    console.log(JSON.stringify(user));
    this.http
        .post<any>(this.loginURL, user, httpOptions)
        .subscribe(
            res => console.log('response : ' + res),
            err => console.log('error : ' + err))
}

这是一个非常标准的 POST 调用,但它总是 returns null,我不明白为什么。 这是NetworkGoogleChrome的标签信息

Chrome的Console信息

我不明白为什么响应是 null。即使我没有有效载荷,它至少应该使 headers 可用 no?

尝试以下操作,

this.http.post(loginUrl,user,httpOptions).map( res =>res).subscribe(data => {
  console.log(data);
});

尝试以下操作:

this.http.post("url", body, {headers: headers, observe: "response"})
   .subscribe(res => console.log(res));

您可以采用相同的 http 选项,但添加注释:response。 header 是来自 http 客户端的 HttpHeaders。例如:headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')