How to send array (a text with commas) as HTTP-param using Rest Assured (Java)

浪尽此生 提交于 2020-07-23 09:12:46

问题


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?


回答1:


Disable URL encoding, simple as that

given().urlEncodingEnabled(false);

Official documentation

Verified locally,



来源:https://stackoverflow.com/questions/61136578/how-to-send-array-a-text-with-commas-as-http-param-using-rest-assured-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!