I am trying to hit a webservice URL with a query parameter as foo & bar with the URL as encoded. To achieve encoding, I am using Apache URIBuilder. The code is as follows:
URIBuilder ub = new URIBuilder("http://example.com/query").setParameter("q", "foo & bar");
URI uri = ub.build();
HttpGet httpget = new HttpGet(uri);
System.out.println(httpget.getURI());
I get the following as output: http://example.com/query?q=+foo+%2526+bar
I am new to this JAR file and have 2 questions:
Why is the space in the query param replaced with a '+' sign and not with %20 special character.
Why is the '&' symbol in the query param getting encoded twice and how to avoid it.