如何在放心的查询参数值中处理特殊字符
在使用Rest Assured时,我正在努力处理查询参数值中的特殊字符.
I'm struggling with handling special character in query parameter value while working with Rest Assured.
在url中(如下所示),我必须传递用管道符号'|'分隔的值.我已将符号编码为值%7C,但是服务调用未给出匹配的响应,而是返回默认响应.
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 %7C XYZ
有趣的是,相同的url可与任何浏览器其余客户端或其他基于Java的解决方案配合使用.
Interesting part is same url works fine with any browser rest client or other java based solution.
REST默认情况下,Assured确保对查询参数执行URL编码.您可以通过以下方式轻松禁用它:
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.