【发布时间】:2020-12-15 21:49:16
【问题描述】:
通过 WebClient(org.springframework.web.reactive.function.client) 获取 post 方法的响应时出现以下错误
org.springframework.core.codec.DecodingException: JSON decoding error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 2]
at org.springframework.http.codec.json.AbstractJackson2Decoder.processException(AbstractJackson2Decoder.java:215)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Ȁ
我尝试使用 failure 更改请求的标头:-
headers.put("Accept-Encoding", "gzip");
或
headers.put("Accept-Encoding", "identity");
是不是webclient因为任何原因无法处理gzip压缩的响应!!
提前致谢!!
【问题讨论】:
-
是的。基本上我从 webclient 得到问题。问题基本上是如何在 webclient 中解决相同的 JSonParseException。
-
你能手动解析payload吗?设置调试器或检查客户端发送的内容并尝试解析它。也尝试使用不同的客户端“postman, curl..etc”发送相同的发布请求
-
是的,当端点在邮递员中发布时,它会给出 JSON 响应。
-
可以使用类似这样的方式测试令牌是否有效:gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7
标签: spring-webclient jsonexception