I am trying to build a URI having a trailing slash but can't happen to find the way to do it with URIBuilder. Is that even possible?
Expected result would be: http://test.com:24/?param1=value1¶m2=value2
@Test
public void ttt(){
final URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme("http");
uriBuilder.setHost("test.com");
uriBuilder.setPort(24);
uriBuilder.addParameter("param1", "value1");
uriBuilder.addParameter("param2", "value2");
System.out.println(uriBuilder.toString());
}
What I get at the moment: http://test.com:24?param1=value1¶m2=value2
Any idea?
There is setPath(str)
method, see URIBuilder.setPath(String)
So your code should look like
@Test
public void ttt(){
final URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme("http");
uriBuilder.setHost("test.com");
uriBuilder.setPort(24);
uriBuilder.setPath("/");
uriBuilder.addParameter("param1", "value1");
uriBuilder.addParameter("param2", "value2");
System.out.println(uriBuilder.toString());
}
Output
http://test.com:24/?param1=value1¶m2=value2