All Products
Search
Document Center

HTTPDNS:Asynchronously resolve domain names to IPv6 addresses

Last Updated:Sep 15, 2022

Notice

If you use HTTPDNS in an IPv6-only network environment, take note of the following points:

  • When you use IP address URLs to make network requests, the formats of IPv4 addresses and IPv6 addresses are different.

    • IPv4: http://1.1.1.1/path

    • IPv6: http://[2001:db8:c000:221::]/path

    As shown in the preceding example, enclose an IPv6 address with brackets in a URL.

    For the convenience of developers, HTTPDNS provides the following IP acquisition operation that adapts to different URL formats: -[HTTPDNS Service getIpByHostAsyncInURLFormat:].

  • When you obtain an IP address by using HTTPDNS and use the IP address to access a URL-based network, you can call the preceding operation to obtain the formatted IP address that complies with the scenario-specific URL, such as *1.1.1.1* and *[2001:db8:c000:221::]*.

    If you only want to get accurate IP address information for something else, you can continue to call the old operation: -[HttpDnsService getIpByHostAsync:].

Enabling IPv6 resolution

Configure whether to enable IPv6 resolution. If IPv6 resolution is enabled, you can initiate requests to resolve domain names to IPv6 addresses.

Notice

  • After you enable IPv6 resolution, call getIPv6ByHostAsync: to use the feature.

  • After you enable IPv6 resolution, the SDK no longer automatically converts resolved IPv4 addresses to IPv6 addresses in an IPv6-only network environment. You can call getIpsByHostAsync: to obtain IPv4 addresses and getIPv6ByHostAsync: to obtain IPv6 addresses.

API operation

 - (void)enableIPv6:(BOOL)enable;

Parameters

Parameter

Type

Required

Description

enable

BOOL

Yes

Specifies whether to enable IPv6 resolution. Default value: NO.

Asynchronous IPv6 resolution of domain names

Note

After you enable the feature, you can asynchronously resolve domain names to IPv6 addresses. On the condition that IPv6 resolution is enabled, if a domain name has a corresponding IPv6 address, the domain name is resolved to the IPv6 address. For example, if the corresponding IPv4 address and IPv6 address of the ipv6.sjtu.edu.cn domain name are 192.168.XX.XX and 2001:da8:8000:1:0:0:XX:XX, respectively, the domain name is resolved to 2001:da8:8000:1:0:0:XX:XX.

Notice

If IPv6 resolution is not enabled, null is returned.

API operation

 - (NSString *)getIPv6ByHostAsync:(NSString *)host;

Parameters

Parameter

Type

Required

Description

host

NSString

Yes

The domain name.

IPv4 and IPv6 resolution at the same time

Note

IPv4 and IPv6 addresses are queried at the same time, and a dictionary is returned. Corresponding value of each key in the dictionary:

IPv4:ALICLOUDHDNS_IPV4

IPv6:ALICLOUDHDNS_IPV6

Format of each key in the dictionary:

{

ALICLOUDHDNS_IPV4: ['xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx'],

ALICLOUDHDNS_IPV6: ['xx:xx:xx:xx:xx:xx:xx:xx', 'xx:xx:xx:xx:xx:xx:xx:xx']

}

API operation

- (NSDictionary <NSString *, NSArray *>*)getIPv4_v6ByHostAsync:(NSString *)host;

Parameters

Parameter

Type

Required

Description

host

NSString

Yes

The domain name.