【问题标题】:How to pass caret symbol in URL?如何在 URL 中传递插入符号?
【发布时间】:2019-03-24 03:46:35
【问题描述】:

我需要像 URL 中的参数值一样传递 ^。例如:

http://localhost:8080/myapp/books?filter=^

但有一个error:java.lang.IllegalArgumentException:在请求目标中发现无效字符。有效字符在 RFC 7230 和 RFC 3986 中定义。我读过,我需要编码。有这样的东西,但它仍然不起作用。我也尝试添加 System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow" ^ ");

但对于 ^ 没有帮助。

我有一个控制器:

@RequestMapping("/books")
public String getBooks(@RequestParam(value = "filter") String filter, Model model)
        throws UnsupportedEncodingException {

        String par = URLEncoder.encode(nameFilter,"UTF-8");
    List<Books> books = (List<Books>) booksService.findAll(filter);
    model.addAttribute("books", books);
    return "getBooks";
}

}

【问题讨论】:

标签: java rest spring-mvc spring-boot url


【解决方案1】:

在向您的 REST Api 发出请求之前尝试对 URI 进行编码

例如,当您使用 JS 时,请阅读以下内容: https://www.w3schools.com/jsref/jsref_encodeURI.asp 在 Java 上:Java URL encoding: URLEncoder vs. URI

祝你好运!

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 2014-10-11
    • 2013-12-10
    • 2017-11-20
    • 2018-06-24
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    相关资源
    最近更新 更多