Distortion
Distortion

Reputation: 1

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

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?

Upvotes: 0

Views: 236

Answers (1)

Wilfred Clement
Wilfred Clement

Reputation: 2774

Disable URL encoding, simple as that

given().urlEncodingEnabled(false);

Official documentation

Verified locally,

enter image description here

Upvotes: 1

Related Questions