5

How to construct a URI like www.google.com/p1/p2?what&k1=v1&k2=v2 using URIBuilder ? When I use Java's URIBuilder.setParameter(), I must pass in an name and a value. How can I construct the above uri without using URIBuilder.setCustomQuery() ?

Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
zeromem
  • 381
  • 1
  • 3
  • 12

3 Answers3

8
UriBuilder builder = new UriBuilder()
    .setScheme("https")
    .setHost("www.google.com")
    .setPath("/p1/p2")
    .addParameter("what",null)
    .addParameter("k1", "v1")
    .addParameter("k2", "v2")
builder.toString();
Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
1

well,, call setParameter(name, null) solve this.

zeromem
  • 381
  • 1
  • 3
  • 12
0

take a look at this java doc for example

UriBuilder.fromPath("{arg1}").fragment("{arg2}").build("foo", "bar")

this code generates foo#bar

or write your own writer it is just a string concatenation