Saffik
Saffik

Reputation: 1003

Java URL encoding escaping special characters

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.

Upvotes: 0

Views: 1160

Answers (1)

Saffik
Saffik

Reputation: 1003

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.

Upvotes: 1

Related Questions