Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(C) Cloudfare DNS over HTTPS

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 C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    const char *url;
    const char *jsonResp;
    HCkJsonObject json;
    int Status;
    BOOL TC;
    BOOL RD;
    BOOL RA;
    BOOL AD;
    BOOL CD;
    int i;
    int count_i;
    const char *name;
    int type;
    int TTL;
    const char *data;
    const char *ipAddr;

    // 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) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        return;
    }

    printf("Response Status Code: %d\n",CkHttp_getLastStatus(http));

    json = CkJsonObject_Create();
    CkJsonObject_Load(json,jsonResp);
    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));

    if (CkHttp_getLastStatus(http) != 200) {
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    // 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) {
        CkJsonObject_putI(json,i);
        name = CkJsonObject_stringOf(json,"Question[i].name");
        type = CkJsonObject_IntOf(json,"Question[i].type");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"Answer");
    // The domain name resolves to 1 or more IP addresses..
    while (i < count_i) {
        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");

        printf("IP Address: %s\n",ipAddr);
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);

    }

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.