URI.ParseServerAuthority Method

Definition

Attempts to parse this URI's authority component, if defined, into user-information, host, and port components.

[Android.Runtime.Register("parseServerAuthority", "()Ljava/net/URI;", "")]
public Java.Net.URI? ParseServerAuthority ();
[<Android.Runtime.Register("parseServerAuthority", "()Ljava/net/URI;", "")>]
member this.ParseServerAuthority : unit -> Java.Net.URI

Returns

URI

A URI whose authority field has been parsed as a server-based authority

Attributes

Exceptions

if the authority part could not be parsed as a server-based authority.

Remarks

Attempts to parse this URI's authority component, if defined, into user-information, host, and port components.

If this URI's authority component has already been recognized as being server-based then it will already have been parsed into user-information, host, and port components. In this case, or if this URI has no authority component, this method simply returns this URI.

Otherwise this method attempts once more to parse the authority component into user-information, host, and port components, and throws an exception describing why the authority component could not be parsed in that way.

This method is provided because the generic URI syntax specified in RFC 2396 cannot always distinguish a malformed server-based authority from a legitimate registry-based authority. It must therefore treat some instances of the former as instances of the latter. The authority component in the URI string "//foo:bar", for example, is not a legal server-based authority but it is legal as a registry-based authority.

In many common situations, for example when working URIs that are known to be either URNs or URLs, the hierarchical URIs being used will always be server-based. They therefore must either be parsed as such or treated as an error. In these cases a statement such as

<blockquote> URIu= new URI(str).parseServerAuthority();</blockquote>

can be used to ensure that u always refers to a URI that, if it has an authority component, has a server-based authority with proper user-information, host, and port components. Invoking this method also ensures that if the authority could not be parsed in that way then an appropriate diagnostic message can be issued based upon the exception that is thrown.

Java documentation for java.net.URI.parseServerAuthority().

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