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

◆ dns_safe_host()

xtd::string xtd::uri::dns_safe_host ( ) const

Gets an unescaped host name that is safe to use for DNS resolution.

Returns
The host part of the URI in a format suitable for DNS resolution; or the original host string, if it is already suitable for resolution.
Exceptions
xtd::invalid_operation_exceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.
Examples
The following example creates a xtd::uri instance from a string. It illustrates the difference between the value returned from xtd::uri::host, which returns the host name or address specified in the URI, and the value returned from xtd::uri::dns_safe_host, which returns an address that is safe to use in DNS resolution.
// Create new Uri using a string address.
auto address = uri("http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm");
// Make the address DNS safe.
// The following outputs "[fe80::200:39ff:fe36:1a2d]".
console::write_line(address.host());
// The following outputs "fe80::200:39ff:fe36:1a2d%254".
console::write_line(address.dns_safe_host());
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.
As explained in Remarks, unescape the host name before resolving it. You can use the xtd::uri::unescape_data_string method to unescape the host name, and you can resolve it by calling the xtd::uri::get_host_entry method.
Remarks
For IPv6 addresses, the brackets ([]) are removed and the xtd::uri::scope_id property is set, if one was specified when this instance was constructed.