Sample code for 30+ languages & platforms
AutoIt

Cloudfare DNS over HTTPS

See more Cloudfare Examples

Cloudflare offers a DNS over HTTPS resolver at: https://cloudflare-dns.com/dns-query

This example demonstrates how to do a DNS lookup for a domain using Cloudfare's HTTPS resolver.

Chilkat AutoIt Downloads

AutoIt
;  This example requires the Chilkat API to have been previously unlocked.
;  See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat.Http")

;  Send the following CURL request:   curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A'

$oHttp.Accept = "application/dns-json"

Local $sUrl = "https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A"

Local $sJsonResp = $oHttp.QuickGetStr($sUrl)
If ($oHttp.LastMethodSuccess <> True) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Response Status Code: " & $oHttp.LastStatus & @CRLF)

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.Load($sJsonResp)
$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)

If ($oHttp.LastStatus <> 200) Then
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

;  Sample output...
;  (See the parsing code below..)
;  

;  {
;    "Status": 0,
;    "TC": false,
;    "RD": true,
;    "RA": true,
;    "AD": false,
;    "CD": false,
;    "Question": [
;      {
;        "name": "chilkat.io.",
;        "type": 1
;      }
;    ],
;    "Answer": [
;      {
;        "name": "chilkat.io.",
;        "type": 1,
;        "TTL": 900,
;        "data": "52.25.83.238"
;      }
;    ]
;  }

;  Use this online tool to generate parsing code from sample JSON: 
;  Generate Parsing Code from JSON

Local $iStatus
Local $bTC
Local $bRD
Local $bRA
Local $bAD
Local $bCD
Local $i
Local $iCount_i
Local $sName
Local $iType
Local $iTTL
Local $sData
Local $sIpAddr

$iStatus = $oJson.IntOf("Status")
$bTC = $oJson.BoolOf("TC")
$bRD = $oJson.BoolOf("RD")
$bRA = $oJson.BoolOf("RA")
$bAD = $oJson.BoolOf("AD")
$bCD = $oJson.BoolOf("CD")
$i = 0
$iCount_i = $oJson.SizeOfArray("Question")
While $i < $iCount_i
    $oJson.I = $i
    $sName = $oJson.StringOf("Question[i].name")
    $iType = $oJson.IntOf("Question[i].type")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJson.SizeOfArray("Answer")
;  The domain name resolves to 1 or more IP addresses..
While $i < $iCount_i
    $oJson.I = $i
    $sName = $oJson.StringOf("Answer[i].name")
    $iType = $oJson.IntOf("Answer[i].type")
    $iTTL = $oJson.IntOf("Answer[i].TTL")
    $sIpAddr = $oJson.StringOf("Answer[i].data")

    ConsoleWrite("IP Address: " & $sIpAddr & @CRLF)
    $i = $i + 1
Wend