xtd 0.2.0
Loading...
Searching...
No Matches

◆ uri() [4/5]

xtd::uri::uri ( const uri base_uri,
const xtd::ustring relative_uri 
)

Initializes a new instance of the xtd::uri class based on the specified base URI and relative URI string.

Parameters
base_uri: The base URI.
relative_uri: The relative URI to add to the base URI.
Exceptions
xtd::uri_format_exceptionThe URI formed by combining base_uri and relative_uri is empty or contains only spaces.
-or-
The scheme specified in the URI formed by combining base_uri and relative_uri is not valid.
-or-
The URI formed by combining base_uri and relative_uri contains too many slashes.
-or-
The password specified in the URI formed by combining base_uri and relative_uri is not valid.
-or-
The host name specified in the URI formed by combining base_uri and relative_uri is not valid.
-or-
The file name specified in the URI formed by combining base_uri and relative_uri is not valid.
-or-
The user name specified in the URI formed by combining base_uri and relative_uri is not valid.
-or-
The host or authority name specified in the URI formed by combining base_uri and relative_uri cannot be terminated by backslashes.
-or-
The port number specified in the URI formed by combining base_uri and relative_uri is not valid or cannot be parsed.
-or-
The length of the URI formed by combining base_uri and relative_uri exceeds 65519 characters.
-or-
The length of the scheme specified in the URI formed by combining base_uri and relative_uri exceeds 1023 characters.
-or-
There is an invalid character sequence in the URI formed by combining base_uri and relative_uri.
-or-
The MS-DOS path specified in uriString must start with c:\.
Examples
The following example creates a new instance of the xtd::uri class by combining the relative URIs http://www.contoso.com and catalog/shownew.htm to form the absolute URI http://www.contoso.com/catalog/shownew.htm.
auto base_uri = uri("http://www.contoso.com");
auto my_uri = uri(base_uri, "catalog/shownew.htm");
console::write_line(my_uri.to_string());
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
uri()=default
Initializes a new instance of the xtd::uri class.
Remarks
This constructor creates a xtd::uri instance by combining the base_uri and the relative_uri. If relative_uri is an absolute URI (containing a scheme, host name, and optionally a port number), the xtd::uri instance is created using only relative_uri.
If the base_uri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of base_uri is to be preserved in the constructed xtd::uri.
Additionally, if the relative_uri begins with a slash, then it will replace any relative part of the base_uri
This constructor does not ensure that the xtd::uri refers to an accessible resource.