使用前后端分离,后端生成token后,使用Postman接口测试,在代码中检验解析时:
Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody()出现了错误:
16:30:35.528 [reactor-http-nio-3] ERROR c.a.g.h.GatewayExceptionHandler - [handle,44] - [网关异常处理]请求路径:/auth/get_tokenstring,异常信息:Unable to read JSON value: {"alh����LL��
com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 5)): only regular white space (\r, \n, \t) is allowed between tokens
看出token数据,在网上找了一轮,很多都说时Spring Cloud Feign请求其他服务时,json解析出了问题:
要求移除以下配置
-
server:
# 配置静态资源启用 gzip 压缩
compression:
enabled: true
或者添加以下配置或改为false
2.feign:
compression:
request:
enabled: false
response:
enabled: false
都试了一遍还是不行。
最后打断点对比生成时的token和请求后获取到的token进行比较发现多了Bearer
无语了,工具使用大意,粗心大意造成的,修改前请求是如图:
这种事错误的请求方式,正确的是要把Bearer去掉,如下
这样就可以正常解析出token了