我已授权将令牌直接放入Http Interceptor
。我现在如何从Angular 4 console logs
获得此令牌?
不幸的是, intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
//const changedReq = req.clone({headers: req.headers.set('Authorization', 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbkB3cC5wbCIsImV4cCI6MTUxMDY2NDM0M30.0iBktdr4-1EzTi1iaQOOfguK7HGVJF7JYkB-AF3uZgJrmKnVESAyKkHoNRzum1Pq5xZ6GJaZC9cbZQ2umMSfLA')});
console.log('req', req);
return next.handle(req).do((event: HttpEvent<any>) => {
console.log('event', event);
if (event instanceof HttpResponse) {
// do stuff with response if you want
}
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
this.ehs.setService(err.status, err.error);
// redirect to login
}
});
}
以下的所有内容都不包含此标题:
query = session.query(User)
def query_to_dict(query):
def _create_dict(r):
return {c.get('name'): getattr(r, c.get('name')) for c in query.column_descriptions}
return [_create_dict(r) for r in query]
答案 0 :(得分:2)
HttpHeaders
是Map
instance的包装器,因此现有标头不会显示在console.log
输出中,因为Map
值未公开。
可以从HttpHeaders
实例中检索标头,因为其API建议:
req.headers.get('authorization');