java.net.URI.create("localhost:8080/foo") // Works
java.net.URI.create("127.0.0.1:8080/foo") // Throws exception
java.net.URI.create("//127.0.0.1:8080/foo") // Works
Is double slash required for when you have the host as an IP Address? I glanced through the RFC for URI - https://www.rfc-editor.org/rfc/rfc3986. But could not find anything pertaining to this.
java.net.URI.createuses the syntax described in RFC 2396.This doesn't produce an exception, but the URI is parsed in a way which you probably don't expect. Its scheme (not host!) is set to
localhost, and the8080/fooisn't port + path, but a scheme-specific part. So this doesn't really work.parses the URL without scheme, as a net_path grammar element (see RFC 2396 for details).
Here's the relevant grammar excerpt from the RFC 2396:
One proper way would be: