Compartir a través de


URI Constructors

Definition

Overloads

URI(String)

Constructs a URI by parsing the given string.

URI(String, String, String)

Constructs a URI from the given components.

URI(String, String, String, String)

Constructs a hierarchical URI from the given components.

URI(String, String, String, String, String)

Constructs a hierarchical URI from the given components.

URI(String, String, String, Int32, String, String, String)

Constructs a hierarchical URI from the given components.

URI(String)

Constructs a URI by parsing the given string.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;)V", "")]
public URI (string? str);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;)V", "")>]
new Java.Net.URI : string -> Java.Net.URI

Parameters

str
String

The string to be parsed into a URI

Attributes

Exceptions

Remarks

Constructs a URI by parsing the given string.

This constructor parses the given string exactly as specified by the grammar in RFC 2396, Appendix&nbsp;A, <b>except for the following deviations:</b>

<ul>

<li>

An empty authority component is permitted as long as it is followed by a non-empty path, a query component, or a fragment component. This allows the parsing of URIs such as "file:///foo/bar", which seems to be the intent of RFC&nbsp;2396 although the grammar does not permit it. If the authority component is empty then the user-information, host, and port components are undefined.

</li>

<li>

Empty relative paths are permitted; this seems to be the intent of RFC&nbsp;2396 although the grammar does not permit it. The primary consequence of this deviation is that a standalone fragment such as "#foo" parses as a relative URI with an empty path and the given fragment, and can be usefully resolved against a base URI.

<li>

IPv4 addresses in host components are parsed rigorously, as specified by RFC 2732: Each element of a dotted-quad address must contain no more than three decimal digits. Each element is further constrained to have a value no greater than 255.

</li>

<li>

Hostnames in host components that comprise only a single domain label are permitted to start with an alphanum character. This seems to be the intent of RFC 2396 section&nbsp;3.2.2 although the grammar does not permit it. The consequence of this deviation is that the authority component of a hierarchical URI such as s://123, will parse as a server-based authority.

</li>

<li>

IPv6 addresses are permitted for the host component. An IPv6 address must be enclosed in square brackets ('[' and ']') as specified by RFC 2732. The IPv6 address itself must parse according to RFC 2373. IPv6 addresses are further constrained to describe no more than sixteen bytes of address information, a constraint implicit in RFC&nbsp;2373 but not expressible in the grammar.

</li>

<li>

Characters in the other category are permitted wherever RFC&nbsp;2396 permits escaped octets, that is, in the user-information, path, query, and fragment components, as well as in the authority component if the authority is registry-based. This allows URIs to contain Unicode characters beyond those in the US-ASCII character set.

</li>

</ul>

Java documentation for java.net.URI.URI(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

URI(String, String, String)

Constructs a URI from the given components.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")]
public URI (string? scheme, string? ssp, string? fragment);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")>]
new Java.Net.URI : string * string * string -> Java.Net.URI

Parameters

scheme
String

Scheme name

ssp
String

Scheme-specific part

fragment
String

Fragment

Attributes

Exceptions

Remarks

Constructs a URI from the given components.

A component may be left undefined by passing null.

This constructor first builds a URI in string form using the given components as follows:

<ol>

<li>

Initially, the result string is empty.

</li>

<li>

If a scheme is given then it is appended to the result, followed by a colon character (':').

</li>

<li>

If a scheme-specific part is given then it is appended. Any character that is not a legal URI character is quoted.

</li>

<li>

Finally, if a fragment is given then a hash character ('#') is appended to the string, followed by the fragment. Any character that is not a legal URI character is quoted.

</li>

</ol>

The resulting URI string is then parsed in order to create the new URI instance as if by invoking the #URI(String) constructor; this may cause a URISyntaxException to be thrown.

Java documentation for java.net.URI.URI(java.lang.String, java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

URI(String, String, String, String)

Constructs a hierarchical URI from the given components.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")]
public URI (string? scheme, string? host, string? path, string? fragment);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")>]
new Java.Net.URI : string * string * string * string -> Java.Net.URI

Parameters

scheme
String

Scheme name

host
String

Host name

path
String

Path

fragment
String

Fragment

Attributes

Exceptions

Remarks

Constructs a hierarchical URI from the given components.

A component may be left undefined by passing null.

This convenience constructor works as if by invoking the seven-argument constructor as follows:

<blockquote> new#URI(String, String, String, int, String, String, String) URI(scheme, null, host, -1, path, null, fragment);</blockquote>

Java documentation for java.net.URI.URI(java.lang.String, java.lang.String, java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

URI(String, String, String, String, String)

Constructs a hierarchical URI from the given components.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")]
public URI (string? scheme, string? authority, string? path, string? query, string? fragment);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")>]
new Java.Net.URI : string * string * string * string * string -> Java.Net.URI

Parameters

scheme
String

Scheme name

authority
String

Authority

path
String

Path

query
String

Query

fragment
String

Fragment

Attributes

Exceptions

Remarks

Constructs a hierarchical URI from the given components.

If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). Otherwise a component of the new URI may be left undefined by passing null for the corresponding parameter.

This constructor first builds a URI string from the given components according to the rules specified in RFC 2396, section&nbsp;5.2, step&nbsp;7:

<ol>

<li>

Initially, the result string is empty.

</li>

<li>

If a scheme is given then it is appended to the result, followed by a colon character (':').

</li>

<li>

If an authority is given then the string "//" is appended, followed by the authority. If the authority contains a literal IPv6 address then the address must be enclosed in square brackets ('[' and ']'). Any character not in the unreserved, punct, escaped, or other categories, and not equal to the commercial-at character ('@'), is quoted.

</li>

<li>

If a path is given then it is appended. Any character not in the unreserved, punct, escaped, or other categories, and not equal to the slash character ('/') or the commercial-at character ('@'), is quoted.

</li>

<li>

If a query is given then a question-mark character ('?') is appended, followed by the query. Any character that is not a legal URI character is quoted.

</li>

<li>

Finally, if a fragment is given then a hash character ('#') is appended, followed by the fragment. Any character that is not a legal URI character is quoted.

</li>

</ol>

The resulting URI string is then parsed as if by invoking the #URI(String) constructor and then invoking the #parseServerAuthority() method upon the result; this may cause a URISyntaxException to be thrown.

Java documentation for java.net.URI.URI(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

URI(String, String, String, Int32, String, String, String)

Constructs a hierarchical URI from the given components.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")]
public URI (string? scheme, string? userInfo, string? host, int port, string? path, string? query, string? fragment);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "")>]
new Java.Net.URI : string * string * string * int * string * string * string -> Java.Net.URI

Parameters

scheme
String

Scheme name

userInfo
String

User name and authorization information

host
String

Host name

port
Int32

Port number

path
String

Path

query
String

Query

fragment
String

Fragment

Attributes

Exceptions

Remarks

Constructs a hierarchical URI from the given components.

If a scheme is given then the path, if also given, must either be empty or begin with a slash character ('/'). Otherwise a component of the new URI may be left undefined by passing null for the corresponding parameter or, in the case of the port parameter, by passing -1.

This constructor first builds a URI string from the given components according to the rules specified in RFC 2396, section&nbsp;5.2, step&nbsp;7:

<ol>

<li>

Initially, the result string is empty.

</li>

<li>

If a scheme is given then it is appended to the result, followed by a colon character (':').

</li>

<li>

If user information, a host, or a port are given then the string "//" is appended.

</li>

<li>

If user information is given then it is appended, followed by a commercial-at character ('@'). Any character not in the unreserved, punct, escaped, or other categories is quoted.

</li>

<li>

If a host is given then it is appended. If the host is a literal IPv6 address but is not enclosed in square brackets ('[' and ']') then the square brackets are added.

</li>

<li>

If a port number is given then a colon character (':') is appended, followed by the port number in decimal.

</li>

<li>

If a path is given then it is appended. Any character not in the unreserved, punct, escaped, or other categories, and not equal to the slash character ('/') or the commercial-at character ('@'), is quoted.

</li>

<li>

If a query is given then a question-mark character ('?') is appended, followed by the query. Any character that is not a legal URI character is quoted.

</li>

<li>

Finally, if a fragment is given then a hash character ('#') is appended, followed by the fragment. Any character that is not a legal URI character is quoted.

</li>

</ol>

The resulting URI string is then parsed as if by invoking the #URI(String) constructor and then invoking the #parseServerAuthority() method upon the result; this may cause a URISyntaxException to be thrown.

Java documentation for java.net.URI.URI(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to