Visual FoxPro
Visual FoxPro
Cloudfare DNS over HTTPS
See more Cloudfare Examples
Cloudflare offers a DNS over HTTPS resolver at: https://cloudflare-dns.com/dns-queryThis example demonstrates how to do a DNS lookup for a domain using Cloudfare's HTTPS resolver.
Chilkat Visual FoxPro Downloads
LOCAL loHttp
LOCAL lcUrl
LOCAL lcJsonResp
LOCAL loJson
LOCAL lnStatus
LOCAL lnTC
LOCAL lnRD
LOCAL lnRA
LOCAL lnAD
LOCAL lnCD
LOCAL i
LOCAL lnCount_i
LOCAL lcName
LOCAL lnType
LOCAL lnTTL
LOCAL lcData
LOCAL lcIpAddr
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
* Send the following CURL request: curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A'
loHttp.Accept = "application/dns-json"
lcUrl = "https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A"
lcJsonResp = loHttp.QuickGetStr(lcUrl)
IF (loHttp.LastMethodSuccess <> 1) THEN
? loHttp.LastErrorText
RELEASE loHttp
CANCEL
ENDIF
? "Response Status Code: " + STR(loHttp.LastStatus)
loJson = CreateObject('Chilkat.JsonObject')
loJson.Load(lcJsonResp)
loJson.EmitCompact = 0
? loJson.Emit()
IF (loHttp.LastStatus <> 200) THEN
? "Failed."
RELEASE loHttp
RELEASE loJson
CANCEL
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
lnStatus = loJson.IntOf("Status")
lnTC = loJson.BoolOf("TC")
lnRD = loJson.BoolOf("RD")
lnRA = loJson.BoolOf("RA")
lnAD = loJson.BoolOf("AD")
lnCD = loJson.BoolOf("CD")
i = 0
lnCount_i = loJson.SizeOfArray("Question")
DO WHILE i < lnCount_i
loJson.I = i
lcName = loJson.StringOf("Question[i].name")
lnType = loJson.IntOf("Question[i].type")
i = i + 1
ENDDO
i = 0
lnCount_i = loJson.SizeOfArray("Answer")
* The domain name resolves to 1 or more IP addresses..
DO WHILE i < lnCount_i
loJson.I = i
lcName = loJson.StringOf("Answer[i].name")
lnType = loJson.IntOf("Answer[i].type")
lnTTL = loJson.IntOf("Answer[i].TTL")
lcIpAddr = loJson.StringOf("Answer[i].data")
? "IP Address: " + lcIpAddr
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson