how to handle Special character in query param val

2019-06-20 15:25发布

问题:

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.

回答1:

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.