All Products
Search
Document Center

:Operations for advanced configurations

Last Updated:Apr 11, 2025

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)

Note

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)

Warning

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)

Note

This operation is added in V2.0.0.

Class

HttpDnsLog

Parameter description

Parameter

Type

Required

Description

logger

ILogger

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)

Warning

This operation is removed in V2.4.0. Use void setLogger(ILogger logger)

Class

HttpDnsService

Parameter definition

Parameter

Type

Required

Description

logger

ILogger

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)

Note

This operation is added in V2.0.0.

Class

HttpDnsLog

Parameter description

Parameter

Type

Required

Description

logger

ILogger

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.

Important
  • 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)

Note

This operation is added in V2.4.2.

Class

InitConfig.Builder

Parameter description

Parameter

Type

Required

Description

region

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)

Warning

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

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)

Note

This operation is added in V2.3.0.

Class

InitConfig.Builder

Parameter definition

Parameter

Type

Required

Description

changer

CacheTtlChanger

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)

Note

This operation is added in V2.4.0.

Class

InitConfig.Builder

Parameter description

Parameter

Type

Required

Description

filter

NotUseHttpDnsFilter

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)

Warning

This operation is deprecated in V2.4.0. Use InitConfig.Builder setNotUseHttpDnsFilter(NotUseHttpDnsFilter filter)

Class

InitConfig.Builder

Parameter description

Parameter

Type

Required

Description

filter

DegradationFilter

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.

Note

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)

Note

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)

Warning

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)

Warning

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)

Note

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)

Warning

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)

Note

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

  • true: enables local DNS resolution.

  • false: disables local DNS resolution.