2

I tried to build a URI using URIBuilder using a specific port and a key,value pair.

URIBuilder builder = new URIBuilder();
URI address        = builder.setScheme("http")
                        .setPath("127.0.0.1")
                        .setPort(12345)
                        .addParameter("key", "value")
                        .build();
System.out.println("BuilderPort is: " + builder.getPort());

System.out.println("URIPort is: " + address.getPort();

Console showing:

BuilderPort is: 12345
URIPort is: -1

Is this a wanted behavior? I know I can use:

public URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)

I wondering for .setPort() method if it will be ignored

Heiniken
  • 21
  • 3

1 Answers1

0

Instead of setPath() you have to use setHost("127.0.0.1") (or in this case setHost("localhost")).

Mabi
  • 441
  • 2
  • 6
  • 17