tencent cloud

HTTPDNS

Product Introduction
Overview
Scenarios
Strengths
Use Limits
Purchase Guide
Billing Overview
Payment Overdue
Getting Started
Activating HTTPDNS
Connecting to HTTPDNS
Operation Guide
Adding a Domain
DNS Statistics Description
Query Monitoring
API Documentation
Configuration Information Description
Querying with HTTP Request Methods
AES/DES Encryption/Decryption
Practical Tutorial of API Connection
SDK Documentation
SDK Quick Access
SDK for iOS
SDK for Android
Access Management
Overview
Sample Access Control Policy
FAQs
HTTPDNS Policy
Privacy Policy
Data Processing And Security Agreement

APIs

PDF
Focus Mode
Font Size
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]/.


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback