PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
oleobject loo_Http
string ls_Url
string ls_JsonResp
oleobject loo_Json
integer li_Status
integer li_TC
integer li_RD
integer li_RA
integer li_AD
integer li_CD
integer i
integer li_Count_i
string ls_Name
integer li_Type
integer li_TTL
string ls_Data
string ls_IpAddr
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Send the following CURL request: curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A'
loo_Http.Accept = "application/dns-json"
ls_Url = "https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A"
ls_JsonResp = loo_Http.QuickGetStr(ls_Url)
if loo_Http.LastMethodSuccess <> 1 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
return
end if
Write-Debug "Response Status Code: " + string(loo_Http.LastStatus)
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.Load(ls_JsonResp)
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()
if loo_Http.LastStatus <> 200 then
Write-Debug "Failed."
destroy loo_Http
destroy loo_Json
return
end if
// 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
li_Status = loo_Json.IntOf("Status")
li_TC = loo_Json.BoolOf("TC")
li_RD = loo_Json.BoolOf("RD")
li_RA = loo_Json.BoolOf("RA")
li_AD = loo_Json.BoolOf("AD")
li_CD = loo_Json.BoolOf("CD")
i = 0
li_Count_i = loo_Json.SizeOfArray("Question")
do while i < li_Count_i
loo_Json.I = i
ls_Name = loo_Json.StringOf("Question[i].name")
li_Type = loo_Json.IntOf("Question[i].type")
i = i + 1
loop
i = 0
li_Count_i = loo_Json.SizeOfArray("Answer")
// The domain name resolves to 1 or more IP addresses..
do while i < li_Count_i
loo_Json.I = i
ls_Name = loo_Json.StringOf("Answer[i].name")
li_Type = loo_Json.IntOf("Answer[i].type")
li_TTL = loo_Json.IntOf("Answer[i].TTL")
ls_IpAddr = loo_Json.StringOf("Answer[i].data")
Write-Debug "IP Address: " + ls_IpAddr
i = i + 1
loop
destroy loo_Http
destroy loo_Json