【发布时间】:2018-12-20 17:38:01
【问题描述】:
开发。环境:Angular 6.0.9 - Spring Boot 2.0.7 - Spring 5.0.7
我有一个无聊的问题。我的 Angular 应用程序看不到请求标头中的令牌。我的后端是春天,邮递员我通常会得到令牌。值得注意的是,在(chrome)浏览器中,状态码是200。
令牌生成器:
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
Authentication auth) throws IOException, ServletException {
String login = ((UsuarioSS) auth.getPrincipal()).getUsername();
String token = jwtUtil.generateToken(login);
response.addHeader("Access-Control-Expose-Headers", "Authorization");
response.addHeader("Authorization", "Bearer " + token);
}
服务登录:
export class LoginService {
constructor(public http: HttpClient) { }
authenticate(credential: Credential) {
return this.http.post(`${API_URL}/sge/login`,credential,{observe:'response',responseType:'text'});
}
}
组件:
onSubmit(){
this.credential = this.loginForm.value;
this.loginService.authenticate(this.credential).subscribe(
response => {
console.log(response)
},
error => {console.log(error)}
)
主机版:
控制台邮递员:
【问题讨论】:
-
你能用
console.log(response.headers.get('Authorization'))代替console.log(response)吗? -
我也试过这个并得到'null'