API overview

更新时间:
复制 MD 格式

Introduction

The API operations provided by the Android software development kit (SDK) are categorized by feature as follows:

  • Configuration operations: SDK initialization, security settings, performance optimization, and network adaptation.

  • Domain name resolution operations: Synchronous, asynchronous, and non-blocking parsing, pre-parsing, and cache management.

  • Troubleshooting and tracing operations: Session tracing, Log Management, and debugging support.

  • Custom parsing operations: Synchronous, asynchronous, and non-blocking custom parsing.

  • Common data structures: Data structures for parsing results, callback functions, custom cache TTL, and domain name parsing filters.

The following classifications are based on the level of interface support:

  • Recommended operations: These operations are recommended for the current SDK version. They feature functional or user experience optimizations.

  • Deprecated operations: These operations are no longer recommended because of feature refactoring or design optimizations. Some operations may be removed in future versions. We recommend that you migrate to the corresponding recommended operations for better performance and stability.

This topic describes all API operations available in the HTTPDNS Android SDK to help you quickly understand and use the features of the SDK.

Interface configuration

Configuration operations are used to initialize and configure the features of the HTTPDNS SDK, such as service instance retrieval, cache policies, network parameters, and security settings. You can use these operations to customize the SDK's behavior based on your application's requirements and to optimize parsing performance and security.

Recommended APIs

Class

Function declaration

Description

Introduced in version

HttpDns

getService(String)

Gets an HTTPDNS service instance.

2.6.3

InitConfig.Builder

setContext(Context)

Sets the application context.

2.6.3

InitConfig.Builder

setSecretKey(String)

Sets the key to add a signature.

2.6.3

InitConfig.Builder

setAesSecretKey(String)

Sets the encryption key.

2.6.3

InitConfig.Builder

setEnableHttps(boolean)

Specifies whether to enable the HTTPS protocol for communication with the server-side.

2.2.2

InitConfig.Builder

setEnableExpiredIp(boolean)

Specifies whether to allow returning expired IP addresses.

2.2.2

InitConfig.Builder

setEnableCacheIp(boolean, long)

Allows the use of local cache that has expired for a period of time.

2.4.3

InitConfig.Builder

setEnableCacheIp(boolean)

Enables the local cache feature.

2.2.2

InitConfig.Builder

setPreResolveAfterNetworkChanged(boolean)

Specifies whether to automatically refresh the local cache when the network changes.

2.4.0

InitConfig.Builder

setTimeoutMillis(int)

Sets the threshold for the parsing timeout.

2.4.0

HttpDnsService

setAuthCurrentTime(long)

Corrects the signature time.

1.3.2

InitConfig.Builder

setRegion(Region)

Sets the region node during initialization.

2.4.2

HttpDnsService

setRegion(Region)

Updates the region node.

2.4.2

HttpDnsService

setRegion(String)

Updates the region node.

2.4.2

InitConfig.Builder

configCacheTtlChanger(CacheTtlChanger)

Customizes the cache duration for parsing results.

2.3.0

InitConfig.Builder

setNotUseHttpDnsFilter(NotUseHttpDnsFilter)

Sets a filter for domain names that do not use HTTPDNS for parsing.

2.4.0

InitConfig.Builder

setIPRankingList(List<IPRankingBean>)

Sets the domain names and probe ports for IP address optimization.

2.3.2

InitConfig.Builder

setSdnsGlobalParams(Map<String, String>)

Sets global parameters for custom parsing.

2.4.0

Deprecated Interfaces

Class

Function declaration

Description

Introduced in version

Deprecated version

Delete a version

HttpDns

getService(Context, String)

Gets an HTTPDNS service instance.

1.3.2

2.6.3

-

HttpDns

getService(Context, String, String)

Gets an HTTPDNS service instance.

1.3.2

2.6.3

-

HttpDnsService

setHTTPSRequestEnabled

Specifies whether to enable the HTTPS protocol for communication with the server-side.

1.3.2

-

2.4.0

HttpDnsService

setExpiredIPEnabled(boolean)

Specifies whether to allow returning expired IP addresses.

1.3.2

-

2.4.0

HttpDnsService

setCachedIPEnabled(boolean)

Specifies whether to enable persistence for cached parsing results.

1.3.2

-

2.4.0

HttpDnsService

setPreResolveAfterNetworkChanged(boolean)

Specifies whether to automatically refresh the local cache when the network changes.

1.3.2

-

2.4.0

InitConfig.Builder

setTimeout(int)

Sets the threshold for the parsing timeout.

2.0.2

2.4.0

-

HttpDnsService

setTimeoutInterval(int)

Sets the threshold for the parsing timeout.

1.3.2

-

2.4.0

HttpDnsService

setLogEnabled(boolean)

Specifies whether to enable log output.

1.3.2

2.3.2

2.4.0

HttpDnsService

setLogger(ILogger)

Sets a log callback.

1.3.2

2.3.2

2.4.0

InitConfig.Builder

setRegion(String)

Sets the region node during initialization.

1.3.2

2.4.2

-

InitConfig.Builder

setDegradationFilter(DegradationFilter)

Sets a filter for domain names that do not use HTTPDNS for parsing.

2.4.0

2.4.0

-

HttpDnsService

setIPRankingList(List<IPRankingBean>)

Sets the domain names and probe ports for IP address optimization.

2.3.2

-

2.4.0

HttpDnsService

setIPProbeList(List<IPRankingBean>)

Sets the domain names and probe ports for IP address optimization.

1.3.2

2.3.2

2.3.2

HttpDnsService

setSdnsGlobalParams(Map<String, String>)

Sets global parameters for custom parsing.

1.3.2

-

2.4.0

Domain name resolution operations

Domain name resolution operations are a core feature of the HTTPDNS SDK. These operations provide multiple methods for domain name resolution, including synchronous, asynchronous, and non-blocking parsing. They support dual-stack resolution for IPv4 and IPv6, can automatically select the optimal resolution policy based on the network environment, and provide pre-parsing and cache management features.

Recommended APIs

Class

Function declaration

Description

Introduced in version

HttpDnsService

setPreResolveHosts(List<String>, RequestIpType)

Sets a list of domain names for pre-parsing.

2.4.0

HttpDnsService

getHttpDnsResultForHostSync(String, RequestIpType)

Parses a domain name synchronously and blocks the thread.

2.3.2

HttpDnsService

getHttpDnsResultForHostAsync(String, RequestIpType, HttpDnsCallback)

Parses a domain name asynchronously and returns the result through a callback.

2.4.0

HttpDnsService

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType)

Performs synchronous, non-blocking parsing. It only checks the cache. If the cache does not exist, it returns empty.

2.4.0

HttpDnsService

cleanHostCache(ArrayList<String>)

Deletes the cache for a specified list of domain names.

2.2.2

Deprecated operations

Class

Function declaration

Description

Introduced in version

This version has been deprecated.

Remove a version

HttpDnsService

getIpByHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to an IPv4 address and returns only one IP address.

2.0.2

2.3.2

-

HttpDnsService

getIPv4ForHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to an IPv4 address and returns only one IP address.

2.3.2

2.4.0

-

HttpDnsService

getIPv6ForHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to an IPv6 address and returns only one IP address.

2.3.2

2.4.0

-

HttpDnsService

getIpsByHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to IPv4 addresses and returns all parsing results.

2.0.2

2.3.2

-

HttpDnsService

getIPv4ListForHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to IPv4 addresses and returns all parsing results.

2.3.2

2.4.0

-

HttpDnsService

getIPv6ByHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to an IPv6 address and returns only one IP address.

2.0.2

2.3.2

-

HttpDnsService

getIPv6sByHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to IPv6 addresses and returns all parsing results.

2.0.2

2.3.2

-

HttpDnsService

getIPv6ListForHostASync(String)

A synchronous, non-blocking parsing operation that resolves to IPv6 addresses and returns all parsing results.

2.3.2

2.4.0

-

HttpDnsService

getAllByHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to IPv4 and IPv6 addresses and returns all parsing results.

2.0.2

2.3.2

-

HttpDnsService

getHttpDnsResultForHostAsync(String)

A synchronous, non-blocking parsing operation that resolves to IPv4 and IPv6 addresses and returns all parsing results.

2.3.2

2.4.0

-

HttpDnsService

getIpsByHostAsync(String, RequestIpType)

A synchronous, non-blocking parsing operation that resolves to IPv4 addresses and returns all parsing results.

2.0.2

2.3.2

-

HttpDnsService

getHttpDnsResultForHostAsync(String, RequestIpType)

A synchronous, non-blocking parsing operation that lets you specify the parsing type and returns all parsing results.

2.0.2

2.4.0

-

Troubleshooting and tracing operations

Troubleshooting and tracing operations are used for problem diagnosis and performance monitoring. They provide features such as session tracing and Log Management. You can use these operations to obtain detailed information about the parsing procedure. This information helps developers debug issues and allows operations and maintenance (O&M) engineers to troubleshoot problems, which improves application observability.

Recommended APIs

Class

Function declaration

Description

Introduced in version

HttpDnsService

getSessionId()

Gets the session ID for the interaction with the HTTPDNS server in the current process.

1.3.2

HttpDnsLog

enable(boolean)

Controls the log output switch.

2.0.2

HttpDnsLog

setLogger(ILogger)

Sets the log callback operation.

2.0.2

HttpDnsLog

removeLogger(ILogger)

Deletes the log callback class.

2.0.2

Custom parsing interface

Custom parsing operations allow you to pass extra parameters for domain name resolution to meet the requirements of special business scenarios. You can use custom parameters to implement fine-grained parsing control, such as passing a business identity. This provides personalized parsing services for different business scenarios.

Recommended APIs

Class

Function declaration

Description

Introduced in version

HttpDnsService

getHttpDnsResultForHostSync(String, RequestIpType, Map<String, String>, String)

A synchronous parsing operation that lets you specify the parsing type.

2.4.0

HttpDnsService

getHttpDnsResultForHostAsync(String, RequestIpType, Map<String, String>, String, HttpDnsCallback)

An asynchronous parsing operation that lets you specify the parsing type.

2.4.0

HttpDnsService

getHttpDnsResultForHostSyncNonBlocking(String, RequestIpType, Map<String, String>, String)

A synchronous, non-blocking operation that lets you specify the parsing type.

2.4.0

Deprecated operations

Class

Function declaration

Description

Introduced in version

Deprecated in version

Removing a version

HttpDnsService

getIpsByHostAsync(String, Map<String,String>, String)

A synchronous, non-blocking operation that parses results of the IPv4 type.

1.3.0

2.3.2

-

HttpDnsService

getHttpDnsResultForHostAsync(String, Map<String, String> , String)

A synchronous, non-blocking operation that parses results of the IPv4 type.

2.0.2

2.4.0

-

HttpDnsService

getIpsByHostAsync(String, RequestIpType, Map<String,String>, String)

A synchronous, non-blocking operation that lets you specify the parsing type.

2.0.2

2.4.0

-

HttpDnsService

getHttpDnsResultForHostAsync(String, RequestIpType, Map<String, String>, String)

A synchronous, non-blocking operation that lets you specify the parsing type.

2.0.2

2.4.0

-

Common data structure interfaces

This section defines the core data types and callback operations used in the SDK. These include data structures for parsing results, callback functions, filters, and configuration enumerations. These definitions provide a unified data model and interaction standard for all features of the SDK.

Recommended APIs

Class

Function declaration

Description

Introduced in version

HTTPDNSResult

getHost()

Gets the parsed domain name.

1.3.2

HTTPDNSResult

getIps()

Gets the IPv4 address array.

1.3.2

HTTPDNSResult

getIpv6s()

Gets the IPv6 address array.

2.0.2

HTTPDNSResult

getExtras()

Gets the extra parameters returned by custom parsing.

1.3.2

HTTPDNSResult

isExpired()

Checks if the parsing result has expired.

2.0.2

HttpDnsCallback

onHttpDnsCompleted(HTTPDNSResult)

The callback function for when parsing is complete.

2.4.0

CacheTtlChanger

changeCacheTtl(String, RequestIpType, int)

The callback function for custom cache TTL.

2.3.0

NotUseHttpDnsFilter

notUseHttpDns(String)

The callback function for setting domain names that do not use HTTPDNS for parsing.

2.4.0

ILogger

log(String)

Logging Interface

1.3.2

Region

-

The region enumeration type.

2.4.2

Deprecated operations

Class

Function declaration

Description

Introduced in version

This version is deprecated.

Remove a version

DegradationFilter

shouldDegradeHttpDNS(String)

Sets a filter for domain names that do not use HTTPDNS for parsing.

2.0.2

2.4.0

-