Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject, Http;
...
procedure TForm1.Button1Click(Sender: TObject);
var
http: HCkHttp;
url: PWideChar;
jsonResp: PWideChar;
json: HCkJsonObject;
Status: Integer;
TC: Boolean;
RD: Boolean;
RA: Boolean;
AD: Boolean;
CD: Boolean;
i: Integer;
count_i: Integer;
name: PWideChar;
type: Integer;
TTL: Integer;
data: PWideChar;
ipAddr: PWideChar;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Send the following CURL request: curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A'
CkHttp_putAccept(http,'application/dns-json');
url := 'https://cloudflare-dns.com/dns-query?name=chilkat.io&type=A';
jsonResp := CkHttp__quickGetStr(http,url);
if (CkHttp_getLastMethodSuccess(http) <> True) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
Memo1.Lines.Add('Response Status Code: ' + IntToStr(CkHttp_getLastStatus(http)));
json := CkJsonObject_Create();
CkJsonObject_Load(json,jsonResp);
CkJsonObject_putEmitCompact(json,False);
Memo1.Lines.Add(CkJsonObject__emit(json));
if (CkHttp_getLastStatus(http) <> 200) then
begin
Memo1.Lines.Add('Failed.');
Exit;
end;
// 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
Status := CkJsonObject_IntOf(json,'Status');
TC := CkJsonObject_BoolOf(json,'TC');
RD := CkJsonObject_BoolOf(json,'RD');
RA := CkJsonObject_BoolOf(json,'RA');
AD := CkJsonObject_BoolOf(json,'AD');
CD := CkJsonObject_BoolOf(json,'CD');
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'Question');
while i < count_i do
begin
CkJsonObject_putI(json,i);
name := CkJsonObject__stringOf(json,'Question[i].name');
type := CkJsonObject_IntOf(json,'Question[i].type');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'Answer');
// The domain name resolves to 1 or more IP addresses..
while i < count_i do
begin
CkJsonObject_putI(json,i);
name := CkJsonObject__stringOf(json,'Answer[i].name');
type := CkJsonObject_IntOf(json,'Answer[i].type');
TTL := CkJsonObject_IntOf(json,'Answer[i].TTL');
ipAddr := CkJsonObject__stringOf(json,'Answer[i].data');
Memo1.Lines.Add('IP Address: ' + ipAddr);
i := i + 1;
end;
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
end;