Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

javascript - not able to access access-token and uid from response headers

I am trying to fetch access-token and uid from response headers of a post request, which looks like this enter image description here

this is how i am trying to achieve it from service side

signup(postObj: any){
let url = environment.apiBaseUrl + "/v1/leads";
return this.http.post(url, postObj,{observe: 'response'});
}

Component side code

this.apartmentService.signup(obj).subscribe(data => {
console.log(data);
this.toastr.success('Registered successfully');
console.log(this.citydata,'this.citydata');

}

enter image description here The method is not giving any response headers. Itried many solutions on internet but nothing works for me.

Any lead would be very helpful


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please try once with the below component side code and check whether required response headers are getting fetched or not -

this.apartmentService.signup(obj).subscribe((data: any) => {
console.log('access token: ', data.headers.get('access-token'));
console.log('uid: ', data.headers.get('uid'));
});

OR

this.apartmentService.signup(obj).subscribe((data: any) => {
console.log('access token: ', JSON.parse(data.headers.get('access-token')));
console.log('uid: ', JSON.parse(data.headers.get('uid')));
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...