tencent cloud

문서 HTTPDNS

APIs

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 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]/.


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백