how to handle Special character in query param value in Rest assured

Parveen Y picture Parveen Y · Aug 2, 2016 · Viewed 8.3k times · Source

I'm struggling with handling special character in query parameter value while working with Rest Assured.

In url (as given below), I have to pass the value which is separated with pipe symbol '|'. I encoded symbol with value %7C however service call doesn't not give matching response instead returns default response.

http://localhost:8080/api/abc?Id=7325860%7CXYZ

Interesting part is same url works fine with any browser rest client or other java based solution.

Answer

Johan picture Johan · Aug 4, 2016

REST Assured performs URL encoding for query parameters by default. You can easily disable it though:

given().urlEncodingEnabled(false).when().get("http://localhost:8080/api/abc?Id=7325860%7CXYZ");

See documentation for more info.