发表于: 2019-08-22 21:11:16
1 755
今天在学如何转存token,从header里取的token,然后转存本地,请求的时候把token添加到header里去
不知道自己思路对不对
首先找到方法
angular+ rxjs 怎么获取response的headers?
如果用的 http
this.http.get('url').subscribe(res => { console.log(res.headers.get('xxx'))
})
如果用的 httpClient
this.httpClient.get('url',{observe:'response'}).subscribe(res => { console.log(res.headers.get('xxx'))
})
这里面的url是当前url吗,那如何获得当前url
获取url
import { PlatformLocation } from '@angular/common';//PlatformLocation 与Location都可以,PlatformLocation 是子集
constructor(private location: PlatformLocation) {
}
for (const i in this.location) {
if (i === 'location') {
this.locationUrl = this.location[i].href;
break;
}
}
整合两个方法获得responseHeaders,自己的代码如下:
无法获取,失败了
评论