tencent cloud

DNS Resolution Optimization
Last updated:2026-02-05 11:09:19
DNS Resolution Optimization
Last updated: 2026-02-05 11:09:19

Introduction

This article describes how to access COS using the HTTPDNS service via the COS SDK.

Feature Overview

The mobile COS SDK uses LocalDNS by default. During DNS resolution, issues such as abnormal resolution, domain hijacking, and cross-network access may occur. By integrating HTTPDNS, these problems can be avoided, addressing challenges caused by abnormal domain resolution in mobile internet services.
Therefore, if you are sensitive to the success rate and latency of COS operations such as uploads and downloads, you can use the HTTPDNS service to access COS.

Prerequisites

Before performing the operations, you need to activate the HTTPDNS service and add the corresponding COS domain names. The detailed steps are as follows:
1. Go to the HTTPDNS console to activate it. For specific operations, see activate HTTPDNS.
2. In the HTTPDNS console, add the COS primary domain myqcloud.com. For specific operations, see add domain.
3. Obtain HTTPDNS configuration information. For specific instructions, see configuration information instructions.
Note:
Although HTTPDNS offers a certain free quota, exceeding it will incur fees. For details, see the HTTPDNS pricing.

Operation Steps

Step 1: HTTPDNS Configuration

Please refer to the HTTPDNS SDK configuration (Android, iOS) for the integration and configuration of the HTTPDNS SDK. The COS SDK automatically configures the SDK access business method by default. You do not need to concern yourself with the SDK access business method (Android, iOS) during the configuration of the HTTPDNS SDK.

Step 2: COS SDK Integration

Android
iOS
1. By initializing the COS Service, obtain the CosXmlService.
2. Integrate HTTPDNS via the addCustomerDNSFetch method of CosXmlService.
// Obtain the CosXmlService
cosXmlService.addCustomerDNSFetch(hostname -> {
String ips = MSDKDnsResolver.getInstance().getAddrByName(hostname);
String[] ipArr = ips.split(";");
if (0 == ipArr.length) {
return Collections.emptyList();
}
List<InetAddress> inetAddressList = new ArrayList<>(ipArr.length);
for (String ip : ipArr) {
if ("0".equals(ip)) {
continue;
}
try {
InetAddress inetAddress = InetAddress.getByName(ip);
inetAddressList.add(inetAddress);
} catch (UnknownHostException ignored) {
}
}
return inetAddressList;
});
1. To integrate HTTPDNS, first add the HTTPDNS library dependency in the Podfile file.
pod 'QCloudCore/DNSLoader' // DNSLoader module, which internally encapsulates Tencent HTTPDNS
2. Import the header file and define the member variable dnsloader.
#import "QCloudHTTPDNSLoader.h"

@property (nonatomic,strong)QCloudHTTPDNSLoader * dnsloader;
3. Configure HTTPDNS parameters by sequentially assigning the configuration parameters generated in Step 1 to their corresponding fields.
QCloudDnsConfig config;
config.appId = @"******"; // Optional. App ID, obtained from the Tencent Cloud console, used for Beacon data reporting (this parameter is invalid if Beacon is not integrated)
config.dnsIp = @"0.0.0.0"; // HTTPDNS server IP
config.dnsId = 1; // Authorization ID, applied for via the Tencent Cloud console and sent via email, used for domain name resolution authentication.
config.dnsKey = @"*******"; // des key
config.encryptType = QCloudHttpDnsEncryptTypeDES; // Controls the encryption type
config.debug = YES; // Whether to enable debug logs. YES: enabled, NO: disabled. It is recommended to enable during the joint debugging phase and disable before the official launch.
config.timeout = 5000; // Optional. Timeout period, unit: ms. If set to 0, it defaults to 2000ms.
self.dnsloader = [[QCloudHTTPDNSLoader alloc] initWithConfig:config];
[QCloudHttpDNS shareDNS].delegate = self.dnsloader;

Example Projects

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback