为什么我无法在拦截的请求中获取标头?

时间:2018-07-06 06:54:01

标签: angular

public refreshToken(){
   let options = {

     headers:new HttpHeaders({
       "refresh_token":"djfhhfahsfkhasdfhksdfhhdff",
     })
   }
   this.http.get(this.baseUrl+"/refresh_token", options)
   .subscribe((res)=>{
     this.storage.set("access_token", res.body.access_token);
     console.log("token refreshed");
   },(err)=>{
     console.log("error refreshing token");
   });
}

在上面的代码中,我为请求设置了'refresh_token'标头。 在httpInterceptor的拦截方法中,我在修改请求之前记录了请求标头,但在那里看不到标头“ refresh_token”。

intercept(req: HttpRequest<any>, next: HttpHandler):
    Observable<HttpEvent<any>> {
    console.log("intercepted");
    console.log(req.headers);
    const authReq = req.clone({
      headers: new HttpHeaders({
        'Content-Type': 'application/json',
        'Authorization': "Bearer " + "fgdfhgfghjgjghjkghkjghjghjgh",
      })
    });
    console.log(authReq.headers)
    return next.handle(authReq)

  }

我在做什么错了?

0 个答案:

没有答案