当我尝试注销时,出现了这个错误。
`core.js:6014 ERROR TypeError: Cannot read property 'length' of undefined
at http.js:165
at Array.forEach (<anonymous>)
at HttpHeaders.lazyInit (http.js:153)
at HttpHeaders.init (http.js:274)
at HttpHeaders.forEach (http.js:376)
at Observable._subscribe (http.js:2342)
at Observable._trySubscribe (Observable.js:42)
at Observable.subscribe (Observable.js:28)
at subscribeTo.js:20
at subscribeToResult (subscribeToResult.js:7)`
但是当我使用Postman发送HTTP请求时,代码起作用。我在使用Postman时成功退出了登录
我的身份验证服务
`logout(user){
let headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': this.token }); //this.token is the value of token(eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX...)
let options = { headers: headers };
localStorage.clear()
this.token=null;
return this.http.post<response>('http://localhost:3000/users/logout',null,options).pipe(map(res=>{
console.log(res)
return res
}))}
这是我订阅此HTTP请求的代码:
onLogout(){
this.authService.logout(this.dataService.storingToken).subscribe(res=>{
console.log(res)
if(res.status===true){
this.router.navigate(["/login"])
}else{
console.log("some error has occurred")
}
})
}