【问题标题】:Netty doesn't allow pipe symbol | and throws ExceptionNetty 不允许管道符号 |并抛出异常
【发布时间】:2020-05-14 06:39:46
【问题描述】:

我的端点是/mz/api/mot/pol/re/pt?Output=1|920222|R1205200130|Success|

我正在使用在 Netty 上运行的 Spring Boot 上的网关应用程序

并面临以下异常,

java.lang.IllegalArgumentException: Illegal character in query at index 46: 
    at java.net.URI.create(URI.java:852) ~[na:1.8.0_242]
    at reactor.netty.http.HttpOperations.resolvePath(HttpOperations.java:300) ~[reactor-netty-0.9.4.RELEASE.jar:0.9.4.RELEASE]
    at reactor.netty.http.server.HttpServerOperations.<init>(HttpServerOperations.java:128) ~[reactor-netty-0.9.4.RELEASE.jar:0.9.4.RELEASE]
    at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:157) ~[reactor-netty-0.9.4.RELEASE.jar:0.9.4.RELEASE]
    at 

同样的错误也发生在 Tomcat 中,我通过设置 relaxedQueryChars 属性解决了它。请建议如何做到这一点。提前致谢。

【问题讨论】:

  • 这与 Netty 无关。您创建了无效的 URL。您必须对查询参数进行编码。

标签: spring spring-boot tomcat netty


【解决方案1】:

您必须在查询字符串中为 netty 编码管道。 “|”将变为 %7C

所以这个:/mz/api/mot/pol/re/pt?Output=1%7C920222%7CR1205200130%7CSuccess

变为:`/mz/api/mot/pol/re/pt?Output=1%7C920222%7CR1205200130%7CSuccess

如果您可以控制客户端,有很多工具可以为您对该字符串进行 URL 编码。

另请参阅: https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html

【讨论】:

  • 感谢您的回复。问题是我无法对网址进行编码。此网址已从某个第 3 方重定向到我的服务。
  • @HannahShanthini 客户端确实对其进行了编码,而您的框架对其进行了解码。您现在必须自己再次对其进行编码。
猜你喜欢
  • 2018-06-14
  • 1970-01-01
  • 2012-08-10
  • 2017-07-27
  • 2011-08-08
  • 1970-01-01
  • 2013-10-23
  • 2019-09-02
相关资源
最近更新 更多