Spring boot 字符串查询参数中的换行符

Spring boot 字符串查询参数中的换行符,spring-boot,restful-url,Spring Boot,Restful Url,我想在restfulapi中的get方法的查询参数中添加换行符 这是我在《邮差》中的最后一个GETURL:- www.localhost:8091/customRule?someString="this is some string \\n on new line" 我得到一个例外:- java.lang.IllegalArgumentException: Invalid character found in the request target [/customRule?someString

我想在restfulapi中的get方法的查询参数中添加换行符

这是我在《邮差》中的最后一个
GET
URL:-

www.localhost:8091/customRule?someString="this is some string \\n on new line"
我得到一个例外:-

java.lang.IllegalArgumentException: Invalid character found in the request target [/customRule?someString=%22this%20is%20some%20string%20\\n%20on%20new%20line%22]. The valid characters are defined in RFC 7230 and RFC 3986

我如何解决这个问题?

我读了一些关于这个主题的文章,但我认为这并不是你想要的答案。但我想到了这样的事情。 在
Java
中,新行字符是“
\n

我们需要对新行字符进行编码

我试过使用这样的小代码:

@GetMapping(value = "/new")
public ResponseEntity<?> newLineCharacter(@RequestParam("newline") String newLine) {
    String s = new StringBuilder("xxx").append(newLine).append("yyy").toString();
    log.info(s);
    return ResponseEntity.ok().build();
}
@GetMapping(value=“/new”)
公共响应性换行符(@RequestParam(“换行”)字符串换行符){
字符串s=newstringbuilder(“xxx”).append(换行符).append(“yyy”).toString();
日志信息;
返回ResponseEntity.ok().build();
}
当我用编码的新行字符
%0A
触发此url时,如下所示:

本地主机:8080/a/新?换行=%0A

我在日志中看到如下输出:

xxx

yyy

但这里似乎有一点需要注意, 在
Linux
Windows
Mac
环境中,新行字符是不同的

你可以看到细节

因此,在我看来,使用新行字符作为查询参数并不是一个好主意


我希望这对你有帮助。

这对你有帮助吗?它建议使用%0A。