我试图在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())
}))
}
我正试图得到这个:header
答案 0 :(得分:0)
看看这个:Get-Full-Response
我在这里尝试过此代码,并且可以正常工作:
this.http.get(this.url, { observe: `response` })
.subscribe((res) => {
console.log(res);
})
我使用了订阅而不是管道。 这是响应:
我不确定这是否有帮助。