See Also: URI Members
A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by .
Component | Example value | Also known as |
---|---|---|
URI.Scheme | http | protocol |
URI.SchemeSpecificPart | //username:password@host:8080/directory/file?query#fragment | |
URI.Authority | username:password@host:8080 | |
URI.UserInfo | username:password | |
URI.Host | host | |
URI.Port | 8080 | |
URI.Path | /directory/file | |
URI.Query | query | |
URI.Fragment | fragment | ref |
Absolute URIs always have a scheme. If its scheme is supported by Java.Net.URL, you can use URI.ToURL to convert an absolute URI to a URL.
Relative URIs do not have a scheme and cannot be converted to URLs. If you have the absolute URI that a relative URI is relative to, you can use URI.Resolve(string) to compute the referenced absolute URI. Symmetrically, you can use URI.Relativize(URI) to compute the relative URI from one URI to another.
java Example
URI absolute = new URI("http://android.com/"); URI relative = new URI("robots.txt"); URI resolved = new URI("http://android.com/robots.txt"); // print "http://android.com/robots.txt" System.out.println(absolute.resolve(relative)); // print "robots.txt" System.out.println(absolute.relativize(resolved));
Opaque URIs have both a scheme and a scheme-specific part that does not begin with the slash character: /. The contents of the scheme-specific part of an opaque URI is not parsed so an opaque URI never has an authority, user info, host, port, path or query. An opaque URIs may have a fragment, however. A typical opaque URI is mailto:robots@example.com.
Component | Example value |
---|---|
Scheme | mailto |
Scheme-specific part | robots@example.com |
Fragment |
Hierarchical URIs may have values for any URL component. They always have a non-null path, though that path may be the empty string.
Component | Legal Characters | Other Constraints | Raw Value | Value |
---|---|---|---|---|
Scheme | 0-9, a-z, A-Z, +-. | First character must be in a-z, A-Z | http | |
Scheme-specific part | 0-9, a-z, A-Z, _-!.~'()*,;:$&+=?/[]@ | Non-ASCII characters okay | //user:pa55w%3Frd@host:80/doc%7Csearch?q=green%20robots | //user:pa55w?rd@host:80/doc|search?q=green robots |
Authority | 0-9, a-z, A-Z, _-!.~'()*,;:$&+=@[] | Non-ASCII characters okay | user:pa55w%3Frd@host:80 | user:pa55w?rd@host:80 |
User Info | 0-9, a-z, A-Z, _-!.~'()*,;:$&+= | Non-ASCII characters okay | user:pa55w%3Frd | user:pa55w?rd |
Host | 0-9, a-z, A-Z, -.[] | Domain name, IPv4 address or [IPv6 address] | host | |
Port | 0-9 | 80 | ||
Path | 0-9, a-z, A-Z, _-!.~'()*,;:$&+=/@ | Non-ASCII characters okay | /doc%7Csearch | /doc|search |
Query | 0-9, a-z, A-Z, _-!.~'()*,;:$&+=?/[]@ | Non-ASCII characters okay | q=green%20robots | q=green robots |
Fragment | 0-9, a-z, A-Z, _-!.~'()*,;:$&+=?/[]@ | Non-ASCII characters okay | over%206%22 | over 6" |
To encode a URI, invoke any of the multiple-parameter constructors of this class. These constructors accept your original strings and encode them into their raw form.
To decode a URI, invoke the single-string constructor, and then use the appropriate accessor methods to get the decoded components.
The Java.Net.URL class can be used to retrieve resources by their URI.