tencent cloud

All product documents
Last updated: 2023-06-12 14:45:52
APIs
Last updated: 2023-06-12 14:45:52

Sync DNS APIs

/**
* HTTPDNS' sync DNS API
* The cache is queried first. If the cache is hit, the result will be returned; otherwise, a sync DNS request will be sent
* The latest DNS query result will be returned after the query is completed
* The returned value string will be separated by semicolon, with the resolved IPv4 address ("0" if DNS query fails) before the semicolon and the resolved IPv6 address ("0" if DNS fails) after it
* Sample response: 121.14.77.221;2402:4e00:1020:1404:0:9227:71a3:83d2
* @param domain Domain (such as www.qq.com)
* @return Set of resolved IP results that correspond to the domain
*/
String ips = MSDKDnsResolver.getInstance().getAddrByName(domain);

/**
* HTTPDNS' batch sync DNS API
* The cache is queried first. If the cache is hit, the result will be returned; otherwise, a sync DNS request will be sent
* The latest DNS query result will be returned after the query is completed
* The returned value `ipSet` is the set of resolved IP addresses
* `ipSet.v4Ips` is the set of resolved IPv4 addresses, which may be `null`
* `ipSet.v6Ips` is the set of resolved IPv6 addresses, which may be `null`
* Sample response for a single domain: IpSet{v4Ips=[121.14.77.201, 121.14.77.221], v6Ips=[2402:4e00:1020:1404:0:9227:71ab:2b74, 2402:4e00:1020:1404:0:9227:71a3:83d2], ips=null}
* Sample response for multiple domains: IpSet{v4Ips=[www.baidu.com:14.215.177.39, www.baidu.com:14.215.177.38, www.youtube.com:104.244.45.246], v6Ips=[www.youtube.com.:2001::1f0:5610], ips=null}
* @param domain Multiple domains can be separated by comma, such as `qq.com,baidu.com`
* @return Set of resolved IP results that correspond to the domain
*/
Ipset ips = MSDKDnsResolver.getInstance().getAddrsByName(domain);

Async DNS APIs

// Async callback. Note that all async requests need to be used together with async callbacks
MSDKDnsResolver.getInstance().setHttpDnsResponseObserver(new HttpDnsResponseObserver() {
@Override
public void onHttpDnsResponse(String tag, String domain, Object ipResultSemicolonSep) {
long elapse = (System.currentTimeMillis() - Long.parseLong(tag));
String lookedUpResult = "[[getAddrByNameAsync]]:ASYNC:::" + ipResultSemicolonSep +
", domain:" + domain + ", tag:" + tag +
", elapse:" + elapse;
}
});

/**
* HTTPDNS' async DNS API (to be used together with async callback)
* The cache is queried first. If the cache is hit, the result will be returned; otherwise, an async DNS request will be sent
* The latest DNS query result will be returned asynchronously after the query is completed
* @param domain Domain (such as www.qq.com)
*/
MSDKDnsResolver.getInstance()
.getAddrByNameAsync(hostname, String.valueOf(System.currentTimeMillis()))

/**
* HTTPDNS' batch async DNS API (to be used together with async callbacks)
* The cache is queried first. If the cache is hit, the result will be returned; otherwise, a sync DNS request will be sent
* The latest DNS query result will be returned asynchronously after the query is completed
* @param domain Multiple domains can be separated by comma, such as `qq.com,baidu.com`
*/
MSDKDnsResolver.getInstance()
.getAddrsByNameAsync(hostname, String.valueOf(System.currentTimeMillis()))
How to improve IPv6 usage
As described above, the result returned for resolving a single domain is in the format of IPv4;IPv6 and that for multiple domains is IpSet{v4Ips=[], v6Ips=[], ips=[]}. You can get IPv6 addresses to make URL requests as needed.
When you make a URL request by using an IPv6 address, you need to enclose the IPv6 address in square brackets, such as http://[64:ff9b::b6fe:7475]/.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon