tencent cloud

All product documents
Integration
Last updated: 2025-02-25 16:23:48
Integration
Last updated: 2025-02-25 16:23:48

Overview

HTTPDNS helps avoid the failure to access the optimal access point during the traditional local DNS of ISPs. It works by replacing the traditional DNS protocol with the HTTP encryption protocol, without using domains throughout the process, which greatly reduces the possibility of DNS hijacking.

Preparations

1. You have activated HTTPDNS as instructed in Activating HTTPDNS.
2. You have added domains to be resolved in the HTTPDNS console as instructed in Adding a Domain.
3. You have applied in the HTTPDNS console for SDK integration as instructed in SDK Activation Process.
4. After activating the service, you have been assigned the configuration information such as authorization ID, AES and DES encryption keys, and HTTPS token. You can also view them on the Development Configuration page.

Configuration information required for using the SDK for iOS:
Authorization ID: The unique ID of a development configuration used in HTTPDNS, namely, the dnsId parameter in the SDK used for DNS authentication.
DES encryption key: The dnsKey parameter in the SDK, which you need to pass in when using the DES encryption method.
AES encryption key: The dnsKey parameter in the SDK, which you need to pass in when using the AES encryption method.
HTTPS encryption token: The token parameter in the SDK, which you need to pass in when using the HTTPS encryption method.
iOS APPID (optional): Obtained from the HTTPDNS console for data reporting.

Installation package structure

Download the latest version of the SDK package here.
Get the open-source repository of the SDK here.
Name
Applicable Scope
MSDKDns.xcframework
Applicable to projects with "Build Setting->C Language Dialect" configured as "GNU++98" and "Build Setting->C++ Standard Library" as "libstdc (GNU C standard library)" .
MSDKDns_intl.xcframework
MSDKDns.xcframework version for Tencent Cloud International
MSDKDns_C11.xcframework
Applicable to projects with "Build Setting->C Language Dialect" and "Build Setting->C Standard Library" configured as "GNU++11" and "libc++(LLVM C standard library with C11 support)", respectively.
MSDKDns_C11_intl.xcframework
MSDKDns_C11.xcframework version for Tencent Cloud International
Note:
If you want to use the version for Tencent Cloud International, obtain the initialization configuration from the HTTPDNS international console.
See Access Documentation for details.

SDK integration

Note:
For more information on quick integration, see SDK Activation Process.
HTTPDNS provides two integration methods for iOS:
Integration using CocoaPods
Manual integration

Integration using CocoaPods

1. Add the following code in the Podfile of the project:
# Applicable to projects with "Build Setting->C++ Language Dialect" configured as **"GNU++98"** and "Build Setting->C++ Standard Library" as **"libstdc++(GNU C++ standard library)"**.
pod 'MSDKDns_intl'
# Applicable to projects with "Build Setting->C++ Language Dialect" and "Build Setting->C++ Standard Library" configured as **"GNU++11"** and **"libc++(LLVM C++ standard library with C++11 support)"**, respectively.
# pod 'MSDKDns_C11_intl'
2. Save, run pod install, and open the project with a file with the .xcworkspace extension.
Note:
For more information on CocoaPods, see CocoaPods.

Manual integration

For the directions of manual integration, see the following demos:
Download the Objective-C demo here.
Download the Swift demo here.
Perform the following steps:
1. Import dependency libraries, drag the framework from the HTTPDNSLibs directory into the corresponding Target, and select Copy items if needed in the pop-up box:
MSDKDns_C11_intl.framework (or MSDKDns_intl.framework, depending on the project configuration)
2. Import system libraries:
libz.tbd
libsqlite3.tbd
libc++ .tbd
Foundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Security.framework
Note:
Add the -ObjC flag in Other Linker Flags.

SDK initialization

Sample API call:
In an Objective-C project:
// Use the following method for a .m file:
DnsConfig config = {
        .dnsId = DNS authorization ID, // Obtain the authorization ID from the HTTPDNS console, as shown in the upper-left corner of the screenshot in the "Preparations" section above.
        .dnsKey = @"Encryption key",
.encryptType = HttpDnsEncryptTypeDES,
        .debug = YES,
        .timeout = 2000,
  };
[[MSDKDns sharedInstance] initConfig: &config];
// Use the following method for a .mm file:
DnsConfig *config = new DnsConfig();
config->dnsId = DNS authorization ID; // Obtain the authorization ID from the HTTPDNS console, as shown in the upper-left corner of the screenshot in the "Preparations" section above.
config->dnsKey = @"Encryption key";
config->encryptType = HttpDnsEncryptTypeDES;
config->debug = YES;
config->timeout = 2000;
[[MSDKDns sharedInstance] initConfig: config];
In a Swift project:
let msdkDns = MSDKDns.sharedInstance() as? MSDKDns;
msdkDns?.initConfig(with: [
"dnsId": "DNS authorization ID", // Obtain the authorization ID from the HTTPDNS console, as shown in the upper-left corner of the screenshot in the "Preparations" section above.
"dnsKey": "Encryption key",
"encryptType": 0, // 0: DES; 1: AES; 2: HTTPS
]);

Integration verification

Log verification

Enable the SDK DEBUG logging (set debug in DnsConfig to YES), find the printed api name:HDNSGetHostByName, data: { ... } log, and check the log info of the local DNS ( ldns_ip in the log) and HTTPDNS ( hdns_ip in the log) to determine whether the connection is successful.
The hdns_ip key indicates the DNS query results of A records provided by HTTPDNS.
The hdns_4a_ips key indicates the DNS query results of AAAA records provided by HTTPDNS.
If hdns_ip or hdns_4a_ips is not empty, the connection is successful.
The ldns_ip key indicates the DNS query results provided by the local DNS.

Notes

If the service on the client is bound to the host, such as the HTTP service or the CDN service of the host, you need to specify the host field of the HTTP header after replacing the domain in the URL with the IP returned by HTTPDNS. Example:
NSURLConnection
NSURLSession
curl
The `WWW` API of Unity
AFNetworking
NSURL *httpDnsURL = [NSURL URLWithString:@"URL obtained by concatenating the resolved IP"];
float timeOut = The set timeout period;
NSMutableURLRequest *mutableReq = [NSMutableURLRequest requestWithURL:httpDnsURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval: timeOut];
[mutableReq setValue:@"original domain" forHTTPHeaderField:@"host"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:mutableReq delegate:self];
[connection start];
NSURL *httpDnsURL = [NSURL URLWithString:@"URL obtained by concatenating the resolved IP"];
float timeOut = The set timeout period;
NSMutableURLRequest *mutableReq = [NSMutableURLRequest requestWithURL:httpDnsURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval: timeOut];
[mutableReq setValue:@"original domain" forHTTPHeaderField:@"host"];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[NSOperationQueue currentQueue]];
NSURLSessionTask *task = [session dataTaskWithRequest:mutableReq];
[task resume];
If you want to access www.qq.com and the IP obtained by HTTPDNS is 192.168.0.111, you can perform a call as follows:
curl -H "host:www.qq.com" http://192.168.0.111/aaa.txt.
string httpDnsURL = "URL obtained by concatenating the resolved IP";
Dictionary<string, string> headers = new Dictionary<string, string> ();
headers["host"] = "Original domain";
WWW conn = new WWW (url, null, headers);
yield return conn;
if (conn.error != null) {
print("error is happened:"+ conn.error);
} else {
print("request ok" + conn.text);
}
NSURL *httpDnsURL = [NSURL URLWithString:@"URL obtained by concatenating the resolved IP"];
float timeOut = The set timeout period;
NSMutableURLRequest *mutableReq = [NSMutableURLRequest requestWithURL:httpDnsURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval: timeOut];
[mutableReq setValue:@"original domain" forHTTPHeaderField:@"host"];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
AFHTTPSessionManager* sessionManager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:config];
sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSURLSessionDataTask* task = [sessionManager GET:originalUrl parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"request complete ==== response: %@ ===== error: nil", responseString);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"request complete ==== response: nil ===== error: %@", error);
}];
[task resume];
Check whether an HTTP proxy is used locally. If an HTTP proxy is used, we recommend you not use HTTPDNS to resolve domains.
Check whether an HTTP proxy is used:
- (BOOL)isUseHTTPProxy {
CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(dicRef, (const void*)kCFNetworkProxiesHTTPProxy);
NSString *proxy = (__bridge NSString *)proxyCFstr;
if (proxy) {
return YES;
} else {
return NO;
}
}
Check whether an HTTPS proxy is used:
- (BOOL)isUseHTTPSProxy {
CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(dicRef, (const void*)kCFNetworkProxiesHTTPSProxy);
NSString *proxy = (__bridge NSString *)proxyCFstr;
if (proxy) {
return YES;
} else {
return NO;
}
}

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

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support