Introduction
The HTTPDNS SDK offers a suite of domain name resolution interfaces and related features, including the following:
Domain name blacklist. For more information, see set HTTPDNS domain name blacklist.
Custom TTL. For more information, see customize resolution result TTL.
IP optimization. For more information, see enable IP optimization.
Set region nodes. For more information, see set region nodes.
Set pre-resolved domain names
Configure the domain names your app will pre-resolve.
setPreResolveHosts
Interface Definition
void setPreResolveHosts(ArrayList<String> hostList)
void setPreResolveHosts(ArrayList<String> hostList, RequestIpType requestIpType)
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
hostList | ArrayList<String> | Yes | An array that consists of the domain names that you want to pre-resolve. If the requestIpType parameter is not specified, the default is RequestIpType.v4. |
requestIpType | RequestIpType | No | The type of IP address to pre-resolve. It is recommended to use RequestIpType.both The types of IP addresses to which the domain name can be resolved. Valid values:
|
Synchronously resolve domain names
The synchronous resolution interface blocks the current thread until it returns a valid resolution result.
This interface first checks the cache. If an active resolution result is present, it returns the cached result. Otherwise, it blocks the calling thread, performs domain name resolution on the working thread, and returns the result upon completion or an empty value if a timeout occurs.
To prevent app stuttering from misuse on the main thread, this interface checks the calling thread. If the main thread is detected, it defaults to the logic of the getHttpDnsResultForHostSyncNonBlocking interface.
The synchronous resolution interface's duration is governed by the timeout configuration. If resolution fails within this period, an empty result is returned.
getHttpDnsResultForHostSync
Interface Definition
HTTPDNSResult getHttpDnsResultForHostSync(String host, RequestIpType requestIpType)
Method added in version 2.4.0.
Class
HttpDnsService
Parameter Definition
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
requestIpType | RequestIpType | Yes | The type of IP address to be resolved. It is recommended to use RequestIpType.both The types of IP addresses to which the domain name can be resolved. Valid values:
|
Return Description
Type | Description |
Resolution result. |
Code Example
val httpdns = HttpDns.getService(applicationContext, accountID, secretKey)
val httpDnsResult = dnsService?.getHttpDnsResultForHostSync("www.aliyun.com", RequestIpType.auto)
HttpDnsService httpdns = HttpDns.getService(applicationContext, accountID, secretKey);
HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSync("www.aliyun.com", RequestIpType.auto);
Asynchronously resolve domain names
The asynchronous resolution interface resolves domain names without blocking the current thread, returning the result via callback.
It first checks the cache and returns any active result via callback. If no active result is available, it performs resolution on the working thread and returns the result via callback upon completion or when a timeout is reached.
The asynchronous resolution interface's duration is controlled by the timeout configuration. If resolution fails within this period, an empty result is returned via callback.
getHttpDnsResultForHostAsync
Interface Definition
void getHttpDnsResultForHostAsync(String host, RequestIpType type, HttpDnsCallback callback)
Method added in version 2.4.0.
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
requestIpType | RequestIpType | Yes | The type of IP address to be resolved. It is recommended to use RequestIpType.both The types of IP addresses to which the domain name can be resolved. Valid values:
|
callback | Yes | The callback interface for the domain name resolution result. |
Code Example
val httpdns = HttpDns.getService(applicationContext, accountID, secretKey)
val httpDnsResult = dnsService?.getHttpDnsResultForHostAsync("www.aliyun.com", RequestIpType.auto, HttpDnsCallback {
httpDnsResult = it
})
HttpDnsService httpdns = HttpDns.getService(applicationContext, accountID, secretKey);
HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostAsync("www.aliyun.com", RequestIpType.auto, new HttpDnsCallback() {
void onHttpDnsCompleted(HTTPDNSResult result) {
}
});
Synchronously non-blocking resolve domain names
The synchronous non-blocking interface resolves domain names without blocking the current thread but may return an empty result.
This interface only queries the cache and returns the result. If no result is available or it has expired, it performs resolution on the working thread and updates the cache for subsequent calls.
getHttpDnsResultForHostSyncNonBlocking
Interface Definition
HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type)
Method added in version 2.4.0.
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
requestIpType | RequestIpType | Yes | The type of IP address to be resolved. It is recommended to use RequestIpType.both The types of IP addresses to which the domain name can be resolved. Valid values:
|
Return Description
Type | Description |
Resolution result. |
Code Example
val httpdns = HttpDns.getService(applicationContext, accountID, secretKey)
val httpDnsResult = dnsService?.getHttpDnsResultForHostSyncNonBlocking("www.aliyun.com", RequestIpType.auto)
HttpDnsService httpdns = HttpDns.getService(applicationContext, accountID, secretKey);
HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSyncNonBlocking("www.aliyun.com", RequestIpType.auto);
getIpByHostAsync
Resolve domain names synchronously without blocking, returning a single IPv4 address.
Interface Definition
String getIpByHostAsync(String host)
As of version 2.3.2, this method is deprecated and may be removed in future releases. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String | The IP address resolved from the domain name is the first IP address in the array returned by the server and may not be the optimal IP address. |
getIPv4ForHostAsync
Resolve domain names synchronously without blocking, returning a single IPv4 address.
Interface Definition
String getIPv4ForHostAsync(String host)
This method was deprecated in version 2.4.0 and may be removed in future versions. For current implementations, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String | The IP address resolved from the domain name is the first IP address in the IPv4 array returned by the server and may not be the optimal IP address. |
getIpsByHostAsync
Resolve domain names synchronously without blocking, and return all IPv4 addresses.
Interface Definition
String[] getIpsByHostAsync(String host)
asynchronously retrieves an array of IP addresses associated with a given hostname.
As of version 2.3.2, this method is deprecated and may be removed in future releases. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
is a feature designed to optimize DNS resolution.
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String[] | All IPv4 addresses. |
getIPv4ListForHostAsync
Resolve domain names synchronously without blocking, returning all IPv4 addresses.
Interface Definition
String[] getIPv4ListForHostAsync(String host)
As of version 2.4.0, this method is deprecated and may be removed in future releases. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String[] | All IPv4 addresses. |
getIPv6ByHostAsync
Resolve domain names synchronously without blocking, returning a single IPv6 address.
Interface Definition
String getIPv6ByHostAsync(String host)
As of version 2.3.2, this method is deprecated and may be removed in future releases. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String | The IP address resolved from the domain name is the first IP address in the IPv6 array returned by the server and may not be the optimal IP address. |
getIPv6ForHostAsync
Resolve domain names synchronously without blocking, returning a single IPv6 address.
Interface Definition
String getIPv6ForHostAsync(String host)
As of version 2.4.0, this method is deprecated and may be removed in future releases. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String | The IP address resolved from the domain name is the first IP address in the IPv6 array returned by the server and may not be the optimal IP address. |
getIPv6sByHostAsync
Resolve domain names synchronously without blocking, and retrieve all associated IPv6 addresses.
Interface Definition
String[] getIPv6sByHostAsync(String host)
This method was deprecated in version 2.3.2 and may be removed in future versions. For current implementations, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String[] | All IPv6 addresses. |
getIPv6ListForHostASync
Resolve domain names synchronously without blocking, and return all IPv6 addresses.
Interface Definition
String[] getIPv6ListForHostASync(String host)
This method was deprecated in version 2.4.0 and may be removed in future versions. For a replacement, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
String[] | All IPv6 addresses. |
getAllByHostAsync
Resolve domain names synchronously without blocking, returning all IPv4 and IPv6 addresses.
Interface Definition
HTTPDNSResult getAllByHostAsync(String host)
retrieves all available DNS information for the specified host asynchronously.
This method was deprecated in version 2.3.2 and may be removed in future versions. For current implementations, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
Resolution result. |
getHttpDnsResultForHostAsync
Resolve domain names synchronously without blocking, returning all IPv4 and IPv6 addresses.
Interface Definition
HTTPDNSResult getHttpDnsResultForHostAsync(String host)
retrieves the asynchronous DNS resolution result for a specified host.
This method was deprecated in version 2.4.0 and may be removed in future versions. For current implementations, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
Return Description
Type | Description |
Resolution result. |
getIpsByHostAsync
Resolve domain names synchronously without blocking, and return all IP addresses associated with the specified IP type.
Interface Definition
HTTPDNSResult getIpsByHostAsync(String host, RequestIpType requestIpType)
retrieves the IP addresses for a host asynchronously, based on the specified IP type.
As of version 2.3.2, this method is deprecated and may be removed in future releases. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
requestIpType | RequestIpType | Yes | The type of IP address to be resolved. It is recommended to use RequestIpType.both |
Return Description
Type | Description |
Resolution result. |
getHttpDnsResultForHostAsync
Resolve domain names synchronously without blocking, and return all IP addresses associated with the specified IP type.
Interface Definition
HTTPDNSResult getHttpDnsResultForHostAsync(String host, RequestIpType type)
retrieves asynchronous HTTPDNS results for a specified host and IP request type.
This method was deprecated in version 2.4.0 and may be removed in future versions. Instead, please use HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType type).
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
host | String | Yes | The domain name to be resolved. |
requestIpType | RequestIpType | Yes | The type of IP address to be resolved. It is recommended to use RequestIpType.both |
Return Description
Type | Description |
Resolution result. |
Clear the cached DNS records of a domain name
To update cached DNS records swiftly when using Alibaba Cloud Domain Name Resolution Service, you can perform the following steps:
Update the domain name's corresponding IP address to ip2 in the HTTPDNS console. The server will recognize the change and clear the cached DNS record containing ip1.
Invoke this operation to remove the domain name xxx.com's DNS record from the local cache.
After clearing the cache, any new request will prompt the server to query the authoritative server for the latest DNS record with ip2, which is then used for resolution.
cleanHostCache
Interface Definition
void cleanHostCache(ArrayList<String> hosts)
Method added in version 2.0.3.
The purge operation clears both the memory and local caches.
Class
HttpDnsService
Parameter Description
Parameter | Type | Required | Description |
hosts | ArrayList<String> | Yes | An array consisting of the domain name whose DNS record you want to clear from the local cache. If you want to clear the records of all domain names, set this parameter to null or an empty array. |