0

I am making a GET request in my java code and the URL that i want to use to perform a GET request is:

http://localhost:1111/sms/v1/222222?startTime=2015-12-29T14%3A00%3A00.000Z&endTime=2015-12-29T15%3A00%3A00.000Z

However it is coming up as:

http://localhost:1111/sms/v1/222222?startTime=2015-12-29T14%253A00%253A00.000Z&endTime=2015-12-29T15%253A00%253A00.000Z

Notice that the following characters are being replaced:

% to %25

How do I make sure my request is sent as I want to specify. My code looks like this:

public static String getRequest(String id, String startTs, String endTs) {
    Response response = givenAuthJson("username", "password")
            .queryParam("startTime", startTs)
            .queryParam("endTime", endTs)
            .get(BASE_URL+"/sms/v1/{id}", id);
    response
            .then()
            .spec(responseSpec);

    return response.asString();
}

And I call this method as:

.getRequest("222222", "2015-12-29T14%3A00%3A00.000Z","2015-12-29T15%3A00%3A00.000Z");

Can you please give an example or answer using the code given? Thanks.

Saffik
  • 911
  • 4
  • 19
  • 45
  • 1
    Is this `RestAssured`? Did you check [this](https://stackoverflow.com/questions/41085365/how-to-pass-query-string-parameters-in-get-url-using-rest-assured)? – BackSlash Mar 12 '18 at 16:35
  • That is %-encoding, which is replacing non-ASCII and special characters with bytes from the character encoding that the server expects (almost always UTF-8 but it's up to the server). Your library is assuming you want that but you've done it already. @BackSlash seems to be onto why. – Tom Blodget Mar 12 '18 at 16:42
  • @BackSlash - Using your advice, It looks better but still the "%" sign causing problems. /sms/v1/222222?startTime=2015-12-29T14%253A00%253A00.000Z&endTime=2015-12-29T15%253A00%253A00.000Z. I updated the question to reflect that. – Saffik Mar 12 '18 at 16:50
  • 1
    You're encoding parameters that are already encoded. The parameters of your method should be `"2015-12-29T14:00:00.000Z", "2015-12-29T15:00:00.000Z"`. – JB Nizet Mar 12 '18 at 17:41

1 Answers1

1

OK - not sure if I'm allowed to answer my own Q but it is for the benefit of all if someone is doing the same thing as me!

I overcame this problem by adding the following

.urlEncodingEnabled(false)

REFERENCE: how to handle Special character in query param value in Rest assured

Thanks for all who helped.

Saffik
  • 911
  • 4
  • 19
  • 45