1e41f4b71Sopenharmony_ci# @ohos.uri (URI String Parsing) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe uri module provides APIs for parsing URI strings that comply with the RFC3986 standard. This standard defines how to encode and parse the identifiers used to locate network resources. The module does not support parsing of URIs in non-standard scenarios. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Modules to Import 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { uri } from '@kit.ArkTS'; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## URI 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciImplements a URI, which provides APIs for determining whether objects are equal as well as standard paths. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci### Attributes 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci| Name| Type| Readable| Writable| Description| 25e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 26e41f4b71Sopenharmony_ci| scheme | string | Yes| No| Scheme in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 27e41f4b71Sopenharmony_ci| userInfo | string | Yes| No| User information in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 28e41f4b71Sopenharmony_ci| host | string | Yes| No| Host name (without the port number) in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 29e41f4b71Sopenharmony_ci| port | string | Yes| No| Port number in the URI.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 30e41f4b71Sopenharmony_ci| path | string | Yes| No| Path in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 31e41f4b71Sopenharmony_ci| query | string | Yes| No| Query parameters in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 32e41f4b71Sopenharmony_ci| fragment | string | Yes| No| Fragments in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 33e41f4b71Sopenharmony_ci| authority | string | Yes| No| Authority in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 34e41f4b71Sopenharmony_ci| ssp | string | Yes| No| Scheme-specific part in the URI. It contains protocol-or scheme-specific information.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 35e41f4b71Sopenharmony_ci| encodedUserInfo<sup>12+</sup> | string | Yes | No | Encoded user information in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 36e41f4b71Sopenharmony_ci| encodedPath<sup>12+</sup> | string | Yes | No | Encoded path in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 37e41f4b71Sopenharmony_ci| encodedQuery<sup>12+</sup> | string | Yes | No | Encoded query parameters in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 38e41f4b71Sopenharmony_ci| encodedFragment<sup>12+</sup> | string | Yes | No | Encoded fragments in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 39e41f4b71Sopenharmony_ci| encodedAuthority<sup>12+</sup> | string | Yes | No | Encoded authority in the URI. If this part does not exist, a null object is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 40e41f4b71Sopenharmony_ci| encodedSSP<sup>12+</sup> | string | Yes | No | Encoded scheme-specific part in the URI.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci### Naming Rules 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciNaming format: 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciA standard URI mainly consists of three parts, as follows: 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci[scheme:]scheme-specific-part[#fragment] 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciThe generic URI syntax consists of a hierarchical sequence of components, as follows: 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci[scheme:][//authority][path][?query][#fragment] 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciIt can be further divided into the following parts: 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci[scheme:][//[user-info@]host[:port]][path][?query][#fragment] 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci- scheme: scheme name, which is separated from scheme-specific-part by a colon (:). The URI that contains the scheme component is an absolute URI, and the URI that does not contain the scheme component is a relative URI. Set this part as required. Example values: **http**, **https**, **ftp**, and **datashare**. 59e41f4b71Sopenharmony_ci- scheme-specific-part: specific part of the URI decoding scheme. It is located between [scheme:] and [#fragment] and consists of [//][authority][path][?query]. The URI that starts with a slash (/) is a hierarchical URI, and the URI that does not start with a slash (/) is an opaque URI. Set this part as required. 60e41f4b71Sopenharmony_ci - authority: decoding authority component of the URI. The value consists of [userinfo@]host[:port]. Set this part as required. 61e41f4b71Sopenharmony_ci - userinfo: user information, which is separated from host by an at sign (@). Set this part as required. 62e41f4b71Sopenharmony_ci - host: host name of the server. This parameter is mandatory when authority exists. 63e41f4b71Sopenharmony_ci - port: port number of the server. The default value is **-1**. Set this part as required. 64e41f4b71Sopenharmony_ci - path: path information, which is located between host and query and separated by a slash (/). Set this part as required. 65e41f4b71Sopenharmony_ci - query: query component, which is located between path and fragment, indicated by the first question mark (?) character, and is in the format of key-value pairs. Multiple key-value pairs are separated by the at sign (&), and the key and value in a pair is separated by the equal sign (=). Set this part as required. 66e41f4b71Sopenharmony_ci- fragment: fragment component, which is separated from scheme-specific-part by the pound key (#). Set this part as required. 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**Example URIs** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci```ts 71e41f4b71Sopenharmony_ciconst result1 = new uri.URI("ftp://ftp.aaa.bbb.ccc/dddd/eee.txt"); 72e41f4b71Sopenharmony_ciconsole.info(result1.host) // ftp.aaa.bbb.ccc 73e41f4b71Sopenharmony_ciconsole.info(result1.fragment) // null 74e41f4b71Sopenharmony_ciconsole.info(result1.path) // /dddd/eee.txt 75e41f4b71Sopenharmony_ciconsole.info(result1.scheme) // ftp 76e41f4b71Sopenharmony_ciconsole.info(result1.userInfo) // null 77e41f4b71Sopenharmony_ciconsole.info(result1.port) // -1 78e41f4b71Sopenharmony_ciconsole.info(result1.query) // null 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciconst result2 = new uri.URI("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#fragment"); 81e41f4b71Sopenharmony_ciconsole.info(result2.host) // spinaltap.micro.umn.edu 82e41f4b71Sopenharmony_ciconsole.info(result2.fragment) // fragment 83e41f4b71Sopenharmony_ciconsole.info(result2.path) // /00/Weather/California/Los Angeles 84e41f4b71Sopenharmony_ciconsole.info(result2.scheme) // gopher 85e41f4b71Sopenharmony_ciconsole.info(result2.userInfo) // null 86e41f4b71Sopenharmony_ciconsole.info(result2.port) //-1 87e41f4b71Sopenharmony_ciconsole.info(result2.query) // null 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ciconst result3 = new uri.URI("datashare:///com.samples.datasharetest.DataShare/DB00/TBL00"); 90e41f4b71Sopenharmony_ciconsole.info(result3.host) // null 91e41f4b71Sopenharmony_ciconsole.info(result3.fragment) // null 92e41f4b71Sopenharmony_ciconsole.info(result3.path) // /com.samples.datasharetest.DataShare/DB00/TBL00 93e41f4b71Sopenharmony_ciconsole.info(result3.scheme) // datashare 94e41f4b71Sopenharmony_ciconsole.info(result3.userInfo) // null 95e41f4b71Sopenharmony_ciconsole.info(result3.port) // -1 96e41f4b71Sopenharmony_ciconsole.info(result3.query) // null 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciconst result4 = new uri.URI("https://username:password@host:8080/directory/file?foo=1&bar=2#fragment"); 99e41f4b71Sopenharmony_ciconsole.info(result4.host) // host 100e41f4b71Sopenharmony_ciconsole.info(result4.fragment) // fragment 101e41f4b71Sopenharmony_ciconsole.info(result4.path) // /directory/file 102e41f4b71Sopenharmony_ciconsole.info(result4.scheme) // https 103e41f4b71Sopenharmony_ciconsole.info(result4.userInfo) // username:password 104e41f4b71Sopenharmony_ciconsole.info(result4.port) // 8080 105e41f4b71Sopenharmony_ciconsole.info(result4.query) // foo=1&bar=2 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ciconst result5 = new uri.URI("dataability:///com.example.DataAbility"); 108e41f4b71Sopenharmony_ciconsole.info(result5.host) // null 109e41f4b71Sopenharmony_ciconsole.info(result5.fragment) // null 110e41f4b71Sopenharmony_ciconsole.info(result5.path) // /com.example.DataAbility: 111e41f4b71Sopenharmony_ciconsole.info(result5.scheme) // dataability 112e41f4b71Sopenharmony_ciconsole.info(result5.userInfo) // null 113e41f4b71Sopenharmony_ciconsole.info(result5.port) // -1 114e41f4b71Sopenharmony_ciconsole.info(result5.query) // null 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ciconst result6 = new uri.URI("https://username:my+name@host:8080/directory/my+file?foo=1&bar=2#fragment"); 117e41f4b71Sopenharmony_ciconsole.info(result6.encodedUserInfo) // username:my+name 118e41f4b71Sopenharmony_ciconsole.info(result6.encodedPath) // /directory/my+file 119e41f4b71Sopenharmony_ciconsole.info(result6.encodedQuery) // foo=1&bar=2 120e41f4b71Sopenharmony_ciconsole.info(result6.encodedFragment) // fragment 121e41f4b71Sopenharmony_ciconsole.info(result6.encodedAuthority) // username:my+name@host:8080 122e41f4b71Sopenharmony_ciconsole.info(result6.encodedSSP) // //username:my+name@host:8080/directory/my+file?foo=1&bar=2 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_cilet result7 = new uri.URI("www.abc.com:8080/directory/file?ab=pppppp#qwer=da"); 125e41f4b71Sopenharmony_ciconsole.log(result7.scheme) // www.abc.com 126e41f4b71Sopenharmony_ciconsole.log(result7.host) // null 127e41f4b71Sopenharmony_ciconsole.log(result7.port) // -1 128e41f4b71Sopenharmony_ciconsole.log(result7.path) // null 129e41f4b71Sopenharmony_ciconsole.log(result7.query) // null 130e41f4b71Sopenharmony_ciconsole.log(result7.authority) // null 131e41f4b71Sopenharmony_ciconsole.log(result7.fragment) // qwer=da 132e41f4b71Sopenharmony_ciconsole.log(result7.ssp) // 8080/directory/file?ab=pppppp 133e41f4b71Sopenharmony_ciconsole.log(result7.checkIsAbsolute()) // true 134e41f4b71Sopenharmony_ci``` 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci### constructor 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ciconstructor(uri: string) 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ciA constructor used to create a URI instance. 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**Parameters** 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 149e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 150e41f4b71Sopenharmony_ci| uri | string | Yes| Input object.| 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Error codes** 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md). 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci| ID| Error Message| 157e41f4b71Sopenharmony_ci| -------- | -------- | 158e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 159e41f4b71Sopenharmony_ci| 10200002 | Invalid uri string. | 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**Example** 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci```ts 164e41f4b71Sopenharmony_cilet mm = 'https://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; 165e41f4b71Sopenharmony_cinew uri.URI(mm); 166e41f4b71Sopenharmony_ci``` 167e41f4b71Sopenharmony_ci```ts 168e41f4b71Sopenharmony_cinew uri.URI('https://username:password@host:8080'); 169e41f4b71Sopenharmony_ci``` 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci### toString 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_citoString(): string 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ciConverts this URI into an encoded string. 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**Return value** 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci| Type| Description| 185e41f4b71Sopenharmony_ci| -------- | -------- | 186e41f4b71Sopenharmony_ci| string | URI in a serialized string.| 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**Example** 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci```ts 191e41f4b71Sopenharmony_ciconst result = new uri.URI('https://username:password@host:8080/directory/file?ab=pppppp#qwer da'); 192e41f4b71Sopenharmony_cilet result1 = result.toString(); // https://username:password@host:8080/directory/file?ab=pppppp#qwer%20da 193e41f4b71Sopenharmony_ci``` 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci### equalsTo<sup>9+</sup> 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ciequalsTo(other: URI): boolean 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ciChecks whether this URI is the same as another URI object. 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**Parameters** 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 208e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 209e41f4b71Sopenharmony_ci| other | [URI](#uri) | Yes| URI object to compare.| 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci**Return value** 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci| Type| Description| 214e41f4b71Sopenharmony_ci| -------- | -------- | 215e41f4b71Sopenharmony_ci| boolean | Returns **true** if the two URIs are the same; returns **false** otherwise.| 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**Error codes** 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci| ID| Error Message| 222e41f4b71Sopenharmony_ci| -------- | -------- | 223e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**Example** 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci```ts 228e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); 229e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); 230e41f4b71Sopenharmony_cilet result = uriInstance.equalsTo(uriInstance1); // true 231e41f4b71Sopenharmony_ci``` 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci### checkIsAbsolute 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_cicheckIsAbsolute(): boolean 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ciChecks whether this URI is an absolute URI (whether the scheme component is defined). 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci**Return value** 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci| Type| Description| 246e41f4b71Sopenharmony_ci| -------- | -------- | 247e41f4b71Sopenharmony_ci| boolean | **true**: The URI is an absolute URI.<br>**false**: The URI is not an absolute URI.| 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**Example** 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci```ts 252e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI('https://username:password@www.qwer.com:8080?query=pppppp'); 253e41f4b71Sopenharmony_ciconsole.info(`${uriInstance.checkIsAbsolute()}`); // true 254e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI('xxx.com/suppliers.htm'); 255e41f4b71Sopenharmony_ciconsole.info(`${uriInstance1.checkIsAbsolute()}`); // false 256e41f4b71Sopenharmony_ci``` 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci### normalize 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_cinormalize(): URI 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ciNormalizes the path of this URI. 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**Return value** 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| Type| Description| 272e41f4b71Sopenharmony_ci| -------- | -------- | 273e41f4b71Sopenharmony_ci| [URI](#uri) | URI with the normalized path.| 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**Example** 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci```ts 278e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI('https://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp'); 279e41f4b71Sopenharmony_ciconsole.info(uriInstance.path); // /path/path1/../path2/./path3 280e41f4b71Sopenharmony_cilet uriInstance1 = uriInstance.normalize(); 281e41f4b71Sopenharmony_ciconsole.info(uriInstance1.path); // /path/path2/path3 282e41f4b71Sopenharmony_ci``` 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci### checkRelative<sup>12+</sup> 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_cicheckRelative(): boolean 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ciChecks whether this URI is a relative URI. A relative URI does not contain the scheme component. 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**Return value** 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci| Type | Description | 297e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ | 298e41f4b71Sopenharmony_ci| boolean | **true**: The URI is a relative URI.<br>**false**: The URI is not a relative URI.| 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci**Example** 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci```ts 303e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://username:password@www.qwer.com:8080?query=p"); 304e41f4b71Sopenharmony_ciconsole.info(`${uriInstance.checkRelative()}`); // false 305e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI("/images/pic.jpg"); 306e41f4b71Sopenharmony_ciconsole.info(`${uriInstance1.checkRelative()}`); // true 307e41f4b71Sopenharmony_ci``` 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci### checkOpaque<sup>12+</sup> 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_cicheckOpaque(): boolean 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ciChecks whether this URI is an opaque URI. The URI that does not start with a slash (/) is an opaque URI. 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci**Return value** 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci| Type | Description | 322e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------- | 323e41f4b71Sopenharmony_ci| boolean | **true**: The URI is an opaque URI.<br>**false**: The URI is not an opaque URI.| 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci**Example** 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci```ts 328e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("http://www.test.com/images/pic.jpg"); 329e41f4b71Sopenharmony_ciconsole.info(`${uriInstance.checkOpaque()}`); // false 330e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI("mailto:user@example.com"); 331e41f4b71Sopenharmony_ciconsole.info(`${uriInstance1.checkOpaque()}`); // true 332e41f4b71Sopenharmony_ci``` 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci### checkHierarchical<sup>12+</sup> 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_cicheckHierarchical(): boolean 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ciChecks whether this URI is a hierarchical URI. The URI that starts with a slash (/) in scheme-specific-part is a hierarchical URI. Relative URIs are also hierarchical. 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Return value** 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci| Type | Description | 347e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 348e41f4b71Sopenharmony_ci| boolean | **true**: The URI is a hierarchical URI.<br>**false**: The URI is not a hierarchical URI.| 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci**Example** 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci```ts 353e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("http://www.test.com/images/pic.jpg"); 354e41f4b71Sopenharmony_ciconsole.info(`${uriInstance.checkHierarchical()}`); // true 355e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI("mailto:user@example.com"); 356e41f4b71Sopenharmony_ciconsole.info(`${uriInstance1.checkHierarchical()}`); // false 357e41f4b71Sopenharmony_ci``` 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci### getQueryValue<sup>12+</sup> 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_cigetQueryValue(key:string): string 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ciObtains the first value of a given key from the query component of this URI. If the query component contains encoded content, this API decodes the key before obtaining the value. 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ciThe query component follows the question mark (?) and consists of key-value pairs, separated by the at sign (&). In each key-value pair, the equal sign (=) is used to connect the key and value. 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci**Parameters** 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 374e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- | 375e41f4b71Sopenharmony_ci| key | string | Yes | Key of the URI query parameter.| 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci**Return value** 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci| Type | Description | 380e41f4b71Sopenharmony_ci| ------ | ----------------------------- | 381e41f4b71Sopenharmony_ci| string | First value obtained. If no value is found, a null object is returned.| 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci**Error codes** 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci| ID| Error Message| 388e41f4b71Sopenharmony_ci| -------- | -------- | 389e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci**Example** 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci```ts 394e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://www.com?param1=value1¶m2=value2"); 395e41f4b71Sopenharmony_ciconsole.info(uriInstance.getQueryValue("param1")); // value1 396e41f4b71Sopenharmony_cilet uriInstance1 = new uri.URI('https://www.zyy.ss?sa%3D=po%7E'); 397e41f4b71Sopenharmony_ciconsole.info(uriInstance1.getQueryValue('sa=')) // po~ 398e41f4b71Sopenharmony_ciconsole.info(uriInstance1.getQueryValue('abc')) // null 399e41f4b71Sopenharmony_ci``` 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci### addQueryValue<sup>12+</sup> 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ciaddQueryValue(key:string, value:string): URI 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ciAdds a query parameter to this URI to create a new URI, while keeping the existing URI unchanged. 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci**Parameters** 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 414e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------ | 415e41f4b71Sopenharmony_ci| key | string | Yes | Key of the query parameter.| 416e41f4b71Sopenharmony_ci| value | string | Yes | Value of the query parameter. | 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**Return value** 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci| Type| Description | 421e41f4b71Sopenharmony_ci| ---- | -------------------------------- | 422e41f4b71Sopenharmony_ci| [URI](#uri) | URI object with the query parameter.| 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci**Error codes** 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci| ID| Error Message| 429e41f4b71Sopenharmony_ci| -------- | -------- | 430e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**Example** 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci```ts 435e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://www.test.com"); 436e41f4b71Sopenharmony_ciconst newRoute = uriInstance.addQueryValue("param1", "hello world"); 437e41f4b71Sopenharmony_ciconsole.info(newRoute.toString()); // https://www.test.com?param1=hello%20world 438e41f4b71Sopenharmony_ci``` 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci### addSegment<sup>12+</sup> 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ciaddSegment(pathSegment:string): URI 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ciEncodes a given field, appends it to the path component of this URI to create a new URI, and returns the new URI, while keeping the existing URI unchanged. 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**Parameters** 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 453e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ------------------ | 454e41f4b71Sopenharmony_ci| pathSegment | string | Yes | Field to be appended to the path component.| 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci**Return value** 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci| Type| Description | 459e41f4b71Sopenharmony_ci| ---- | -------------------------------- | 460e41f4b71Sopenharmony_ci| [URI](#uri) | URI object with the appended field.| 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci**Error codes** 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci| ID| Error Message| 467e41f4b71Sopenharmony_ci| -------- | -------- | 468e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci**Example** 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci```ts 473e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("http://www.test.com"); 474e41f4b71Sopenharmony_ciconst newRoute = uriInstance.addSegment("my image.jpg"); 475e41f4b71Sopenharmony_ciconsole.info(newRoute.toString()); // http://www.test.com/my%20image.jpg 476e41f4b71Sopenharmony_ci``` 477e41f4b71Sopenharmony_ci 478e41f4b71Sopenharmony_ci### addEncodedSegment<sup>12+</sup> 479e41f4b71Sopenharmony_ci 480e41f4b71Sopenharmony_ciaddEncodedSegment(pathSegment:string): URI 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ciAppends an encoded field to the path component of this URI to create a new URI and returns the new URI, while keeping the existing URI unchanged. 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**Parameters** 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 491e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ------------------ | 492e41f4b71Sopenharmony_ci| pathSegment | string | Yes | Encoded field to be appended to the path component.| 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci**Return value** 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci| Type| Description | 497e41f4b71Sopenharmony_ci| ---- | -------------------------------- | 498e41f4b71Sopenharmony_ci| [URI](#uri) | URI object with the appended field.| 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci**Error codes** 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci| ID| Error Message| 505e41f4b71Sopenharmony_ci| -------- | -------- | 506e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci**Example** 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci```ts 511e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("http://www.test.com"); 512e41f4b71Sopenharmony_ciconst newRoute = uriInstance.addEncodedSegment("my%20image.jpg"); 513e41f4b71Sopenharmony_ciconsole.info(newRoute.toString()); // http://www.test.com/my%20image.jpg 514e41f4b71Sopenharmony_ci``` 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci### getQueryNames<sup>12+</sup> 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_cigetQueryNames(): string[] 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ciObtains all non-repeated keys in the query component of this URI. The query component follows the question mark (?) and consists of key-value pairs, separated by the at sign (&). In each key-value pair, the equal sign (=) is used to connect the key and value. 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci**Return value** 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci| Type | Description | 529e41f4b71Sopenharmony_ci| ----------- | ----------------------------------- | 530e41f4b71Sopenharmony_ci| string[] | Non-repeated keys in the query component.| 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**Example** 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci```ts 535e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://www.test.com?param1=value1¶m2=value2"); 536e41f4b71Sopenharmony_ciconst paramNames = uriInstance.getQueryNames(); 537e41f4b71Sopenharmony_ciconsole.info(Array.from(paramNames).toString()); // param1,param2 538e41f4b71Sopenharmony_ci``` 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci### getQueryValues<sup>12+</sup> 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_cigetQueryValues(key:string): string[] 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ciObtains the values of a given key from the query component of this URI. If the query component contains encoded content, this API decodes the keys before obtaining the values. 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ciThe query component follows the question mark (?) and consists of key-value pairs, separated by the at sign (&). In each key-value pair, the equal sign (=) is used to connect the key and value. 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci**Parameters** 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 555e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- | 556e41f4b71Sopenharmony_ci| key | string | Yes | Key of the URI query parameter.| 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci**Return value** 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_ci| Type | Description | 561e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 562e41f4b71Sopenharmony_ci| string[] | Array of values obtained. If no value is found, an empty string array [] is returned.| 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci**Error codes** 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci| ID| Error Message| 569e41f4b71Sopenharmony_ci| -------- | -------- | 570e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci**Example** 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci```ts 575e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://www.test.com/search?query=name&query=my"); 576e41f4b71Sopenharmony_ciconsole.info(uriInstance.getQueryValues("query").toString()); // name,my 577e41f4b71Sopenharmony_ciconsole.info(JSON.stringify(uriInstance.getQueryValues("abc"))); // [] 578e41f4b71Sopenharmony_ci``` 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ci### getBooleanQueryValue<sup>12+</sup> 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_cigetBooleanQueryValue(key:string,defaultValue:boolean): boolean 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ciObtains the value of the Boolean type of a query parameter in this URI. 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci**Parameters** 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 593e41f4b71Sopenharmony_ci| ------------ | ------- | ---- | ------------------------------------- | 594e41f4b71Sopenharmony_ci| key | string | Yes | Name of the query parameter. | 595e41f4b71Sopenharmony_ci| defaultValue | boolean | Yes | Default value.| 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci**Return value** 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci| Type | Description | 600e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------- | 601e41f4b71Sopenharmony_ci| boolean | If the specified query parameter does not exist, the default value is returned. If the first value of the query parameter is **false** or **0**, **false** is returned. Otherwise, **true** is returned.| 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci**Error codes** 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci| ID| Error Message| 608e41f4b71Sopenharmony_ci| -------- | -------- | 609e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci**Example** 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci```ts 614e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://www.test.com/search?active=true"); 615e41f4b71Sopenharmony_ciconsole.info(`${uriInstance.getBooleanQueryValue("active", false)}`); // true 616e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI("https://www.test.com/search"); 617e41f4b71Sopenharmony_ciconsole.info(`${uriInstance1.getBooleanQueryValue("active", false)}`); // false 618e41f4b71Sopenharmony_ciconst uriInstance2 = new uri.URI("https://www.test.com/search?active=aa&active=false"); 619e41f4b71Sopenharmony_ciconsole.info(`${uriInstance2.getBooleanQueryValue("active", false)}`); // true 620e41f4b71Sopenharmony_ciconst uriInstance3 = new uri.URI("https://www.test.com/search?active=0"); 621e41f4b71Sopenharmony_ciconsole.info(`${uriInstance3.getBooleanQueryValue("active", true)}`); // false 622e41f4b71Sopenharmony_ci``` 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci### clearQuery<sup>12+</sup> 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ciclearQuery(): URI 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ciClears the query component of this URI to create a new URI, while keeping the existing URI object unchanged. 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci**Return value** 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci| Type| Description | 637e41f4b71Sopenharmony_ci| ---- | ------------------------------------- | 638e41f4b71Sopenharmony_ci| [URI](#uri) | URI object whose query component has been cleared.| 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci**Example** 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci```ts 643e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("https://www.test.com?param1=value1"); 644e41f4b71Sopenharmony_ciconsole.info(uriInstance.clearQuery().toString()); // https://www.test.com 645e41f4b71Sopenharmony_ci``` 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ci### getLastSegment<sup>12+</sup> 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_cigetLastSegment(): string 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ciObtains the last segment of this URI. A path includes multiple segments, separated by slashes (/). The part that ends with a slash is not a segment. 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci**Return value** 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci| Type| Description | 660e41f4b71Sopenharmony_ci| ---- | ----------------------------- | 661e41f4b71Sopenharmony_ci| string | Last segment of the URI.| 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci**Example** 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci```ts 666e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("content://com.test.provider/files/image.jpg"); 667e41f4b71Sopenharmony_ciconsole.info(uriInstance.getLastSegment()); // image.jpg 668e41f4b71Sopenharmony_ci``` 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci### getSegment<sup>12+</sup> 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_cigetSegment(): string[] 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_ciObtains all segments of this URI. 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci**Return value** 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ci| Type | Description | 683e41f4b71Sopenharmony_ci| -------- | --------------------------- | 684e41f4b71Sopenharmony_ci| string[] | All segments of this URI.| 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci**Example** 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci```ts 689e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI("http://www.test.com/path/to/image.jpg"); 690e41f4b71Sopenharmony_ciconsole.info(uriInstance.getSegment().toString()); // path,to,image.jpg 691e41f4b71Sopenharmony_ci``` 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci### createFromParts<sup>12+</sup> 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_cicreateFromParts(scheme: string, ssp: string, fragment: string): URI 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ciCreates a URI based on the provided scheme, scheme-specific-part, and fragment components. 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci**Parameters** 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 706e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------- | 707e41f4b71Sopenharmony_ci| scheme | string | Yes | Scheme of the URI. | 708e41f4b71Sopenharmony_ci| ssp | string | Yes | Scheme-specific-part of the URI.| 709e41f4b71Sopenharmony_ci| fragment | string | Yes | Fragment of this URI. The fragment component is the part following the number sign (#). | 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci**Return value** 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci| Type| Description | 714e41f4b71Sopenharmony_ci| ---- | ------------------------------------------------- | 715e41f4b71Sopenharmony_ci| [URI](#uri) | URI object obtained.| 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci**Error codes** 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci| ID| Error Message| 722e41f4b71Sopenharmony_ci| -------- | -------- | 723e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**Example** 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci```ts 728e41f4b71Sopenharmony_ciconst uriInstance = uri.URI.createFromParts("mailto", "no body", "top"); 729e41f4b71Sopenharmony_ciconsole.info(uriInstance.toString()); // mailto:no%20body#top 730e41f4b71Sopenharmony_ci``` 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci### equals<sup>(deprecated)</sup> 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ciequals(other: URI): boolean 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ciChecks whether this URI is the same as another URI object. 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci> **NOTE** 739e41f4b71Sopenharmony_ci> 740e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [equalsTo<sup>9+</sup>](#equalsto9) instead. 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci**Parameters** 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 747e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 748e41f4b71Sopenharmony_ci| other | [URI](#uri) | Yes| URI object to compare.| 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ci**Return value** 751e41f4b71Sopenharmony_ci 752e41f4b71Sopenharmony_ci| Type| Description| 753e41f4b71Sopenharmony_ci| -------- | -------- | 754e41f4b71Sopenharmony_ci| boolean | Returns **true** if the two URIs are the same; returns **false** otherwise.| 755e41f4b71Sopenharmony_ci 756e41f4b71Sopenharmony_ci**Example** 757e41f4b71Sopenharmony_ci 758e41f4b71Sopenharmony_ci```ts 759e41f4b71Sopenharmony_ciconst uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); 760e41f4b71Sopenharmony_ciconst uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); 761e41f4b71Sopenharmony_ciuriInstance.equals(uriInstance1); // true 762e41f4b71Sopenharmony_ci``` 763