Harmony DoH integration guide

更新时间:
复制 MD 格式

Integrate DNS-over-HTTPS (DoH) into your HarmonyOS applications to prevent DNS hijacking, improve resolution accuracy, and reduce latency.

Overview

With HTTPDNS DoH integration, your HarmonyOS applications can prevent domain name hijacking, improve DNS scheduling precision, accelerate DNS record propagation, and reduce resolution latency.

Get the DoH address

  1. Go to the Alibaba Cloud DNS - HTTPDNS console.

  2. Click access configuration and enable the encrypted address in the Method 3: DoT/DoH-based access section.

    After you enable the encrypted address, an address table appears. In the DoH column, get your encrypted DoH address. The address format is https://{account-id}.alidns.com/dns-query.

Integration

Use in network requests

Pass the encrypted DoH URL from the console as the dnsOverHttps parameter in your HTTP request configuration.

let httpRequest = http.createHttp();
httpRequest.request(
  "https://www.aliyun.com",
  {
    dnsOverHttps: "https://*****-****2cik1m8wysgb.alidns.com/dns-query",
    method: http.RequestMethod.GET, 
    header: [{
      'Content-Type': 'application/json'
    }],
    expectDataType: http.HttpDataType.STRING, 
    usingCache: false,
    priority: 1, 
    connectTimeout: 3000, 
    readTimeout: 3000,
    usingProxy: false, 
  }, (err: BusinessError, data: http.HttpResponse) => {
 
  }
);

Use in a webview

Call web_webview.WebviewController.setHttpDns to set the webview secure DNS mode to automatic and pass your DoH URL.

web_webview.WebviewController.setHttpDns(web_webview.SecureDnsMode.AUTO, "https://*****-****2cik1m8wysgb.alidns.com/dns-query")