所以我有一个如下所示的帖子,我发送一个POST请求登录,响应为空 -符合预期,很好-但我需要访问“授权”标头。
我找不到任何访问方式。
const data = {email: "email",password: "password"};
this.http.post(`/login`,data).pipe(
tap(resp => {
console.log(resp); // it will be an empty string
return resp;
})).subscribe((resp: any) => {
console.log(resp.headers.get('Authorization')); // error: Cannot read property 'headers' of null
});
更新 受TheUnreal的答案启发,我添加了选项
this.http.post(`/login`,data,{observe: 'response'} )...
现在,我可以访问某些标头,例如“ Cache-Control”。
可能我需要从服务器端表达其余标头
Sam Walpole在评论部分中正确,此问题的大部分内容都在他提供的链接上得到了解答-签出。