Hello, I've been trying to use HttpURLConnection to connect to a web server using its IPv6 link-local address.
There are two issues with this: - HttpURLConnection work with URLs with the official % syntax (only the informal one) for the scope ID (normally required for link-local addresses). Indeed, http://[fe80::a00:27ff:aaaa:aaaa%eth0]/ (for example) can be used to send a request, but http://[fe80::a00:27ff:aaaa:aaaa%25eth0]/ will not send a request at all ("java.net.SocketException: Network is unreachable..."). The difference is in the encoding of % (which separates the actual IP address from the scope ID). RFC 6874 (Section 2) says, "According to URI syntax [RFC3986], "%" is always treated as an escape character in a URI, so, according to the established URI syntax [RFC3986] any occurrences of literal "%" symbols in a URI MUST be percent-encoded and represented in the form "%25"." - HttpURLConnection sends the scope ID in the Host header, i.e. "Host: [fe80::a00:27ff:aaaa:aaaa%eth0]" instead of "Host: [fe80::a00:27ff:aaaa:aaaa]". Unfortunately, this doesn't seem to be allowed by RFC 4007, and this causes Apache Httpd to return a 400 error status. (There are more details in this Apache Httpd issue: https://issues.apache.org/bugzilla/show_bug.cgi?id=35122#c4 ) The only workaround I've found was to set the Host header manually, but this also requires enabling "sun.net.http.allowRestrictedHeaders". These problems are present in the latest Java 7 release and in the Java 8 early release. I'm not sure if this has already been reported or discussed. If not, would it be possible to address it in future releases? Best wishes, Bruno.