简体   繁体   English

Angular 8 HttpClient GET 响应不返回自定义标头

[英]Angular 8 HttpClient GET response not returning the custom headers

im trying to get the response header after http request and i cant get it...我试图在 http 请求后获取响应标头,但我无法获取它...

headers: HttpHeaders;
httpOptions;

  constructor(private http: HttpClient) {
    const token = localStorage.getItem("token");
    this.headers = new HttpHeaders({
      "Content-Type": "application/x-www-form-urlencoded"
    }).set("x-auth-token", token);

    this.httpOptions = {
    headers: this.headers,
    responseType: "text" as "json",
    observe: "response"
};}


test<T>(url: string) {
    return this.http.get<T>(url, this.httpOptions).pipe(
      tap((res: HttpResponse<any>) => {
        console.log(res.headers.keys())
      }))
  }

im trying to get this: header我试图得到这个:标题

take a look at this: Get-Full-Response看看这个:获得完全响应

I tried this code here and it works:我在这里尝试了这段代码,它有效:

    this.http.get(this.url, { observe: `response` })
    .subscribe((res) => {
      console.log(res);
    })

I used subscribe instead of pipe.我使用订阅而不是管道。 This was the response:这是回应:

Response printed on console控制台上打印的响应

I'm not sure if this was helpfull.我不确定这是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM