HTTPDNS provides domain name resolution services via an HTTP API. To access the nearest service node and ensure high availability, dynamic service scheduling capabilities are offered. This document describes the process for obtaining the service IP address in real time through the scheduling interface.
Scenarios
HTTPDNS offers an official SDK for domain name resolution services. The SDK handles the automatic retrieval, updating, and maintenance of service IP addresses, allowing you to complete the resolution by invoking the interface. However, in some scenarios, you might prefer not to integrate the SDK and instead use the official HTTPDNS HTTP API directly. In such cases, it's important to know how to obtain, update, and maintain the service node IP address list to ensure nearby scheduling and high availability for domain name resolution.
To facilitate this, we provide a scheduling interface in the form of an HTTP API. Before using HTTPDNS for resolution, you should invoke this interface to retrieve the service endpoint. The process is as follows:
Embed a default list of HTTPDNS Startup IP addresses in your application. Upon startup, select any IP (or domain name) from this list to initiate a request and invoke the scheduling interface.
The scheduling interface will identify the nearest and most reliable HTTPDNS service node based on the request's source address.
The scheduling interface returns a list of service IP addresses for the identified node in the response.
Select any IP address from this list to invoke the resolution interface for domain name resolution.
If the application restarts or a network switch occurs, you can use the scheduling interface to initiate a scheduling request again to obtain a new service address list.
By following these steps, you can maintain an updated and nearby list of HTTPDNS service addresses with high availability.
Using the logic described, you can retrieve, refresh, and manage a list of nearby, highly available HTTPDNS service addresses.
The official HTTPDNS SDK already includes this functionality. This guide is for situations where the SDK is not an option.
Glossary
Scheduling service: A service that provides the scheduling interface mentioned in this document. It returns the service IP address list and other relevant scheduling information based on the source IP of the request. Typically, you only need to consider the returned IP address list.
Resolution service: The HTTPDNS resolution service interface that resolves domain names to their corresponding IP addresses. For more information, see the single domain name resolution document.
Startup IP: The initial IP (or domain name) used to access the scheduling service. It is utilized to retrieve the latest Service IP address list.
Service IP: The IP used to access the resolution service for domain name resolution.
Access process
The access process is illustrated below:
Review the HTTPDNS startup IP list.
NoteThe Startup IP should be hardcoded into the app. Multiple Startup IPs are provided for redundancy. If a request to the scheduling interface fails, try another Startup IP.
Use a Startup IP to access the scheduling service and obtain the Service IP list.
NoteThe scheduling service supports both HTTP and HTTPS. For direct HTTPS connections, refer to the section Verify Server Identity When Using HTTPS Requests for server verification details.
The Startup IP is exclusively for accessing the scheduling service.
Invoke the resolution service using a Service IP.
As needed, use the startup IP to access the scheduling service, update the service IP list, and ensure its validity.
Note(Recommended) Update the service IP address list upon a cold start.
(Recommended) Update the service IP address list when switching network environments.
(Recommended) Refresh the service IP address list at least every 8 hours.
Update immediately if the service IP list fails to resolve after retries.
The service IP list provided by the resolution service requires an update mechanism. Using a fixed list for an extended period may pose stability risks.
Specific description of the scheduling interface
URL: https://{startup IP}/{account_id}/ss
The {account_id} is your unique HTTPDNS identifier, retrievable from the HTTPDNS console.
Request Method: GET
Optional Parameter Description One:
Optional parameters aid in troubleshooting scheduling anomalies. For more details, see the how to troubleshoot resolution anomalies using the "session tracking scheme".
Name | Required | Description |
sid | Optional | The session ID that is generated when the app starts and used to mark a separate app lifecycle. The session ID is in the following format: [a-zA-Z0-9]{12} |
net | Optional | The network at the OS layer when a request is initiated. Valid values: 5g, 4g, 3g, 2g, wifi, and unknown. |
bssid | Optional | The basic service set identifier (BSSID) of the Wi-Fi environment. BSSIDs are used to mark different Wi-Fi networks. |
Optional Parameter Description Two:
Name | Required | Description |
n | Optional | The random number to be signed. The number must be a hexadecimal number and must be 8 to 16 characters in length. Example: abcdef2345. |
t | Optional | The number of seconds since January 1, 1970 (a positive integer with a fixed length of 10). Important The offset between the client time and server time must be less than 150 seconds. You can modify the time based on the Date parameter in the response header. |
s | Optional | The signature that is generated with the secret. You can view the secret in the HTTPDNS console. Calculation method: s=md5sum(n-secret-t), For example, if n=abcdef2345,secret=123456,t=1632912372, the ASCII code of "abcdef2345-123456-1632912372" is signed to be: de7be63a9f19cf11e9d455d7d4f23cb4. |
Verify Server Identity When Using HTTPS Requests:
When using HTTPS to request the scheduling interface, a valid certificate with the hostname 203.107.1.1 will be provided, regardless of the requested IP. Manually ignore the hostname error in the certificate and verify that the certificate's hostname is 203.107.1.1.
The scheduling interface will include a signature in the
X-Checksum-HmacMD5
field of the response header. If security is a concern, validate the returned results using this signature.
Return Result Signature Logic:
Assuming the secretKey is IAmASecret, the random number n is 2EUenAaShVfy, the current timestamp is 1568802250, and the response content is:
{"service_ip":["203.107.1.33"],"service_ipv6":["64:ff9b::cb6b:121"]}
;Request URL:
http://{startup IP}/{account_id}/ss?n=2EUenAaShVfy&t=1568802250
The signature is calculated as:
hmacMD5("IAmASecret", "2EUenAaShVfy-{"service_ip":["203.107.1.33"],"service_ipv6":["64:ff9b::cb6b:121"]}-1568802250")
=3C74A498A00EEE6C5E7C599B3B882658
The response header will then include the following:
X-Checksum-HmacMD5: 3C74A498A00EEE6C5E7C599B3B882658
The secretKey is available in the "HTTPDNS console > development configuration > authentication secretkey" section.
Return Example:
A successful request will return an HTTP status code of 200 and a JSON-formatted response. Example:
{
"service_ip": [
"203.107.1.33"
],
"service_ipv6": [
"64:ff9b::cb6b:121"
]
}
Field | Description |
service_ip | The IPv4 service IP list. Generally, you only need to use the IPs in this list to invoke the resolution service. |
service_ipv6 | The IPv6 service IP list. In special scenarios, you can use the v6 IPs in this list to invoke the resolution service. |
If a request fails, an HTTP status code of 4xx or 5xx and an error code will be returned in a JSON-formatted response. Example:
{
"code": "MissingArgument"
}
Status code description
Error code | HTTP status code | Description |
MissingArgument | 400 | A required parameter is not specified. |
TimeOutOfSync | 400 | The time offset is greater than or equal to 150 seconds. Modify the time based on the Date parameter in the response header. |
InvalidNonce | 400 | The random number does not meet the requirements. |
InvalidTimestamp | 403 | The timestamp format is invalid. |
AccountNotExists | 403 | The account does not exist or is disabled, or the domain name is not added to the HTTPDNS console. |
InternalError | 500 | Internal server error |