Specify whether to allow HTTPDNS to display logs
You can specify whether to enable HTTPDNS logs. By default, HTTPDNS logs are disabled.
Enable
Operation definition
void enable(boolean enable)
This operation is added in V2.0.0.
Class
HttpDnsLog
Parameter description
Parameter | Type | Required | Description |
enable | boolean | Yes | Specifies whether to display logs on Logcat. |
Sample code
HttpDnsLog.enable(shouldPrintLog)
HttpDnsLog.enable(shouldPrintLog);
Setlogenabled
Operation definition
void setLogEnabled(boolean enable)
This operation is removed in V2.4.0. Use void enable(boolean enable)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
enable | boolean | Yes | Specifies whether to display logs on Logcat. |
Configure a callback class to receive SDK logs
You can configure a callback class to receive SDK logs.
Setlogger
Adds a callback class for logs.
Operation definition
void setLogger(ILogger logger)
This operation is added in V2.0.0.
Class
HttpDnsLog
Parameter description
Parameter | Type | Required | Description |
logger | Yes | You can call the ILogger operation to configure callbacks for SDK logs. This allows you to display and store the logs based on your business requirements. |
Sample code
HttpDnsLog.setLogger { s ->
Log.d(
"HttpDnsSDK",
"resultILogger:$s"
)
}
HttpDnsLog.setLogger(new ILogger() {
@Override
public void log(String s) {
Log.d("HttpDnsSDK", "resultILogger:" + s);
}
});
Setlogger
Adds a callback class for logs.
Operation definition
void setLogger(ILogger logger)
This operation is removed in V2.4.0. Use void setLogger(ILogger logger)
Class
HttpDnsService
Parameter definition
Parameter | Type | Required | Description |
logger | Yes | You can call the ILogger operation to configure callbacks for SDK logs. This allows you to display and store the logs based on your business requirements. |
Removelogger
Removes a callback class for logs.
Operation definition
void removeLogger(ILogger logger)
This operation is added in V2.0.0.
Class
HttpDnsLog
Parameter description
Parameter | Type | Required | Description |
logger | Yes | The log that you added. |
Sample code
HttpDnsLog.removeLogger(logger)
HttpDnsLog.removeLogger(logger);
Calibrate the signature time of an app
After you call this operation, the time on your device is calibrated each time a network request is initiated. If you do not call this operation, the time on the device prevails.
Scenario: The time on a mobile phone is inaccurate.
The calibration takes effect within one lifecycle of an app. After the app is restarted, you must call this operation again.
A time service is required. The time service can be a self-managed time service that supports simple timestamp operations. After you obtain the accurate time by using the time service, specify the time in the calibration operation. This way, the SDK can obtain the difference between the accurate time and the time on the device.
Setauthcurrenttime
Operation definition
void setAuthCurrentTime(long time)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
time | long | Yes | The timestamp of the current time. |
Sample code
val httpdns = HttpDns.getService(accountID)
httpdns?.setAuthCurrentTime(System.currentTimeMillis())
HttpDnsService httpdns = HttpDns.getService(accountID);
httpdns.setAuthCurrentTime(System.currentTimeMillis());
Specify a region
If you want to use HTTPDNS on your app in a region outside the Chinese mainland, you can configure a startup service node of the SDK to improve the resolution efficiency. After you configure the node, the SDK uses the node for domain name resolution and the subsequent scheduling node list updates.
Setregion
Specifies the initial region.
Operation definition
InitConfig.Builder setRegion(Region region)
This operation is added in V2.4.2.
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
region | Yes | The region that you want to specify. Specify a region outside the Chinese mainland. |
Setregion
Specifies the initial region.
Operation definition
InitConfig.Builder setRegion(String region)
The operation is added in V1.3.2 and is deprecated in V2.4.2.
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
region | String | Yes | The region that you want to specify. Specify a region outside the Chinese mainland. Valid values: hk (China (Hong Kong)), sg (Singapore), de (Germany), and us (United States). If you specify a region, the service node in the region is returned. If you do not specify this parameter, the service node in the Chinese mainland is used. |
Sample code
InitConfig.Builder()
.setRegion("hk");
new InitConfig.Builder()
.setRegion("hk");
Setregion
Updates a region.
Operation definition
void setRegion(Region region)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
region | Yes | The region that you want to specify. Specify a region outside the Chinese mainland. |
Setregion
Updates a region.
Operation definition
void setRegion(String region)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
region | String | Yes | The region that you want to specify. Specify a region outside the Chinese mainland. Valid values: hk (China (Hong Kong)), sg (Singapore), de (Germany), and us (United States). If you specify a region, the service node in the region is returned. Important If you want to use HTTPDNS on your app in a region outside the Chinese mainland, configure a suitable service node outside the Chinese mainland. |
Custom TTL for resolution results
By default, each resolution result uses the TTL provided by the server to determine expiration. To modify the TTL of a resolution result, use the following API operation.
Configcachettlchanger
Operation definition
InitConfig.Builder configCacheTtlChanger(CacheTtlChanger changer)
This operation is added in V2.3.0.
Class
InitConfig.Builder
Parameter definition
Parameter | Type | Required | Description |
changer | Yes | The custom TTL. |
Sample code
InitConfig.Builder().configCacheTtlChanger { host, requestIpType, ttl ->
if (TextUtils.equals(host, "www.aliyun.com")) {
// Use www.aliyun.com as an example
ttl * 10
} else ttl
}
new InitConfig.Builder().configCacheTtlChanger(new CacheTtlChanger() {
@Override
public int changeCacheTtl(String host, RequestIpType requestIpType, int ttl) {
// Use www.aliyun.com as an example
if (TextUtils.equals(host, "www.aliyun.com")) {
return ttl * 10;
}
return ttl;
}
});
Configure the HTTPDNS domain name blacklist
If you do not want to resolve specific domain names by using HTTPDNS, filter out the domain names by using this API operation. The filtered domain names return an empty resolution result, and you must use local DNS servers for resolution.
SetNotUseHttpDnsFilter
Operation definition
InitConfig.Builder setNotUseHttpDnsFilter(NotUseHttpDnsFilter filter)
This operation is added in V2.4.0.
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
filter | Yes | The blacklist policy. |
Sample code
InitConfig.Builder().setNotUseHttpDnsFilter { hostName ->
TextUtils.equals(
hostName,
"www.aliyun.com"
)
}
new InitConfig.Builder().setNotUseHttpDnsFilter(new NotUseHttpDnsFilter() {
@Override
public boolean notUseHttpDns(String hostName) {
return TextUtils.equals(hostName, "www.aliyun.com");
}
});
Setdegradationfilter
Operation definition
InitConfig.Builder setDegradationFilter(DegradationFilter filter)
This operation is deprecated in V2.4.0. Use InitConfig.Builder setNotUseHttpDnsFilter(NotUseHttpDnsFilter filter)
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
filter | Yes | The blacklist policy. |
Enable IP address precedence
You can configure an IP address list for ranking. After you call this operation, if the corresponding domain name is resolved, the SDK performs IP speed testing on the returned IP addresses and dynamically sorts the list to ensure that the first IP address is the optimal one.
HTTPDNS SDK for Android V1.1.5 and later support this operation. Only IPv4 addresses are supported.
SetIPRankingList
Operation definition
InitConfig.Builder setIPRankingList(List<IPRankingBean> ipRankingList)
This operation is added in V2.3.2.
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
ipRankingList | List<IPRankingBean> | Yes | You can configure an IP address list for ranking. After you call this operation, if the corresponding domain name is resolved, the SDK performs IP speed testing on the returned IP addresses and dynamically sorts the list to ensure that the first IP address is the optimal one. |
Sample code
val list = ArrayList<IPRankingBean>()
list.add(IPRankingBean("www.aliyun.com", 8080))
InitConfig.Builder().setIPRankingList(list)
ArrayList<IPRankingBean> list = new ArrayList<IPRankingBean>();
list.add(new IPRankingBean("www.aliyun.com", 8080));
new InitConfig.Builder().setIPRankingList(list);
SetIPRankingList
Operation definition
void setIPRankingList(List<IPRankingBean> ipRankingList)
This operation is removed in V2.4.0. Use InitConfig.Builder setIPRankingList(List ipRankingList)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
ipRankingList | List<IPRankingBean> | Yes | You can configure an IP address list for ranking. After you call this operation, if the corresponding domain name is resolved, the SDK performs IP speed testing on the returned IP addresses and dynamically sorts the list to ensure that the first IP address is the optimal one. |
SetIPProbeList
Operation definition
void setIPProbeList(List<IPRankingBean> ipProbeList)
This operation is removed in V2.4.0. Use InitConfig.Builder setIPRankingList(List ipRankingList)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
ipProbeList | List<IPProbeItem> | Yes | You can configure an IP address list for ranking. After you call this operation, if the corresponding domain name is resolved, the SDK performs IP speed testing on the returned IP addresses and dynamically sorts the list to ensure that the first IP address is the optimal one. |
Configure global parameters for custom resolution
This global parameter does not affect the additional parameter settings of the custom resolution operation. Global parameters can be used with the additional parameters.
SetSdnsGlobalParams
Operation definition
InitConfig.Builder setSdnsGlobalParams(Map<String, String> params)
This operation is added in V2.4.0.
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
params | Map<String, String> | Yes | The global parameter, which is used for custom resolution. Each custom resolution request includes the global parameter. |
Sample code
val params: MutableMap<String, String> = HashMap()
params["level"] = "1"
InitConfig.Builder()
.setSdnsGlobalParams(params)
Map<String, String> params = new HashMap<>();
params.put("level", "1");
new InitConfig.Builder()
.setSdnsGlobalParams(params);
SetSdnsGlobalParams
Operation definition
void setSdnsGlobalParams(Map<String, String> params)
This operation is removed in V2.4.0. Use InitConfig.Builder setSdnsGlobalParams(Map params)
Class
HttpDnsService
Parameter description
Parameter | Type | Required | Description |
params | Map<String, String> | Yes | The global parameter, which is used for custom resolution. Each custom resolution request includes the global parameter. |
Configure local DNS resolution
If you allow local Domain Name System (DNS) resolution, when HTTPDNS fails to resolve a domain name, the SDK uses local DNS to resolve the domain name and returns the resolution result. By default, local DNS resolution is not allowed.
SetEnableDegradationLocalDns
Operation definition
InitConfig.Builder setEnableDegradationLocalDns(boolean enableDegradation)
This operation is added in V2.4.2. By default, local DNS resolution is not allowed.
Class
InitConfig.Builder
Parameter description
Parameter | Type | Required | Description |
enableDegradation | boolean | Yes |
|