【发布时间】:2018-07-31 16:22:02
【问题描述】:
我正在尝试在 JWT 上构建我的身份验证。我正在使用 Spring 过滤器来实现该目标,并且在成功登录时返回带有一个标头(授权)的正面(200)响应。不幸的是,我的 Angular 客户端仍然遇到 JSON 解析问题。
客户端代码:
this.http.post<HttpResponse<void>>(EndPoint.LOGIN,
{'username': username, 'password': password } ,
{'headers' : new HttpHeaders ({'Content-Type' : 'application/json', 'responseType': 'text'})})
.subscribe(response => console.log(response.headers.get('Authorization')))
;
回复:
authorization →Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJHZXJhbHQiLCJleHAiOjE1MjAwNTk4MzN9.813r4QmVgrnrsm4HwZID1M56hD42PLe0BvbCu-bQoQWSnxllOE0iAjS-fc-BI8R8eGGE0WPSSL0OaKxz2lxDjA
content-length →0
错误:
message : "Unexpected end of JSON input"
它的工作原理就像 Postman 等 REST 客户端的魅力。
我尝试了多种方法来完成这项工作:
- 将 responseType 设置为文本
- 在响应正文中添加一些内容(错误已更改 - 它无法解析新响应正文的首字母)
- 在没有通用 HttpResponse 对象的情况下发布
现在运气不好。
【问题讨论】: