0

I need to pass ^ like a value of parameter in URL. For example:

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

But have an error:java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986. I've read, that I need to encode. Have something like this, but it still doesn't work. I also try to add System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow" ^ ");

but for ^ it doen't help.

I have a controller:

@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";
}

}

unor
  • 92,415
  • 26
  • 211
  • 360
  • Try [http://localhost:8080/myapp/books?filter=%5E](http://localhost:8080/myapp/books?filter=%5E). See [HTML Encoding](https://www.w3schools.com/tags/ref_urlencode.asp) – Mark Oct 19 '18 at 09:09

2 Answers2

0

Try to follow this, it will help:

https://secure.n-able.com/webhelp/NC_9-1-0_SO_en/Content/SA_docs/API_Level_Integration/API_Integration_URLEncoding.html

@Mark’s comment is also correct.

unor
  • 92,415
  • 26
  • 211
  • 360
kumar
  • 497
  • 4
  • 12
0

Try encoding the URI before doing a request to your REST Api

For instance, when you're using JS read this: https://www.w3schools.com/jsref/jsref_encodeURI.asp On Java: Java URL encoding: URLEncoder vs. URI

Goodluck!

Pim
  • 554
  • 3
  • 12