如何使用 Rest Assured (Java) 将数组(带逗号的文本)作为 HTTP 参数发送 [英] How to send array (a text with commas) as HTTP-param using Rest Assured (Java)
本文介绍了如何使用 Rest Assured (Java) 将数组(带逗号的文本)作为 HTTP 参数发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Rest Assured 框架 (Java).
我需要在 get 请求中将整数数组作为 http-param 发送:
I use Rest Assured framework (Java).
I need to send integer array as http-param in get request: http://example.com:8080/myservice?data_ids=11,22,33
Integer[] ids = new Integer[] {11, 22, 33};
...
RequestSpecificationImpl request = (RequestSpecificationImpl)RestAssured.given();
request.baseUri("http://example.com");
request.port(8080);
request.basePath("/myservice");
...
String ids_as_string = Arrays.toString(ids).replaceAll("\\s|[\\[]|[]]", "");
request.params("data_ids", ids_as_string);
System.out.println("Params: " + request.getRequestParams().toString());
System.out.println("URI" + request.getURI());
What I see in the console:
Params: {data_ids=11,22,33}
URI: http://example.com:8080/myservice?data_ids=11%2C22%2C33
Why do my commas transform into '%2C'?
What needs to be done to ensure that commas are passed as they should?
解决方案
Disable URL encoding, simple as that
given().urlEncodingEnabled(false);
Verified locally,
这篇关于如何使用 Rest Assured (Java) 将数组(带逗号的文本)作为 HTTP 参数发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文