We are a consumer of a Rest API, where we are passing query parameters. We are using Map<String, List>. But we call the API, our producer is getting some special characters for our values. For ex-
List queryParamters = new ArrayList(); queryParameters.add("ABC");
final Map<String, List> finalMap = new HashMap<>();
finalMap.put("column", Collections.singletonList(queryParamters+""));
when we call our API, our producer gets "GET /server-url/product?column=%5ABC%5D HTTP/1.1" but our expectation is to send them ABC not %5ABC%5D.
Can we enforce not to add special characters and our producer gets what we expect?
There's nothing wrong with the URI, it is just being encoded.
The %5B
and %5D
characters you are getting is because you are passing an ArrayList object as a query parameter. If your URI was not encoded, it would look like this:
GET /server-url/product?column=[ABC] HTTP/1.1
If the column
parameter has just one value (as the example you gave), use a String object (not an ArrayList). The result would be like this:
GET /server-url/product?column=ABC HTTP/1.1
But if you really need to specify a list of values as URL parameters (and be able to receive them as a list in the backend side), I would recommend you to repeat the parameters, like this:
GET /server-url/product?column=ABC&column=BCD HTTP/1.1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.