为什么我在使用Angular的HttpClient时只获取到两个标头?

huangapple go评论74阅读模式
英文:

Why I get only two headers in Angular using HttpClient?

问题

I'm trying to get all headers from the response to a post method:

this.http.post<User>(this.url, user, {
    observe: 'response',
    responseType: 'json',
})
.subscribe((res) => {
    console.log('Headers: ' + JSON.stringify(res.headers));
});
}

earlier:

url = 'http://localhost:8080/user/login';
constructor(private http: HttpClient) {}

I followed most tutorials and stackoverflow answers, but I get only two headers:
Headers: {"normalizedNames":{},"lazyUpdate":null}

When I tried with postman and curl everything works fine, that is I get all the headers, but not in Angular (I'm using version Angular CLI: 15.2.8)

英文:

I'm trying to get all headers from the response to a post method:

this.http.post&lt;User&gt;(this.url, user, {
        observe: &#39;response&#39;,
        responseType: &#39;json&#39;,
      })
      .subscribe((res) =&gt; {
        console.log(&#39;Headers: &#39; + JSON.stringify(res.headers));
      });
}

earlier:

url = &#39;http://localhost:8080/user/login&#39;;
constructor(private http: HttpClient) {}

I followed most tutorials and stackoverflow answers, but I get only two headers:
Headers: {"normalizedNames":{},"lazyUpdate":null}

When I tried with postman and curl everything works fine, that is I get all the headers, but not in Angular (I'm using version Angular CLI: 15.2.8)

答案1

得分: 1

请检查这个链接 - https://stackoverflow.com/questions/52443706/angular-httpclient-missing-response-headers

在您的情况下,似乎第二个答案可能会对您有帮助,关于标头的延迟加载。

英文:

Check this one - https://stackoverflow.com/questions/52443706/angular-httpclient-missing-response-headers

In your case seems that second answer might help you, about headers being lazy loaded

huangapple
  • 本文由 发表于 2023年5月17日 17:54:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270804.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定