Chilkat Examples

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

MFC Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Bitfinex v2 REST
Bluzone
BrickLink
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Mastercard

MedTunnel
MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter
UniPin
VoiceBase
Vonage
Walmart
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yousign
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(MFC) WordPress Basic Authentication with miniOrange Plugin

See more WordPress Examples

Demonstrates basic username/password authentication using the miniOrange API Authentication plugin.

For more information, see https://wordpress.org/plugins/wp-rest-api-authentication/

Chilkat C/C++ Library Downloads

MS Visual C/C++ Libs

See Also: Using MFC CString in Chilkat

#include <CkHttp.h>
#include <CkStringBuilder.h>
#include <CkJsonArray.h>
#include <CkDtObj.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    CkString strOut;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http;
    bool success;

    // Implements the following CURL command:

    // curl -X GET --user wp_username:wp_password https://www.yoursite.com/wp-json/wp/v2/posts?page=1

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    http.put_Login("wp_username");
    http.put_Password("wp_password");
    http.put_BasicAuth(true);

    CkStringBuilder sbResponseBody;
    success = http.QuickGetSb("https://www.yoursite.com/wp-json/wp/v2/posts?page=1",sbResponseBody);
    if (success == false) {
        strOut.append(http.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    CkJsonArray jarrResp;
    jarrResp.LoadSb(sbResponseBody);
    jarrResp.put_EmitCompact(false);

    strOut.append("Response Body:");
    strOut.append("\r\n");
    strOut.append(jarrResp.emit());
    strOut.append("\r\n");

    int respStatusCode = http.get_LastStatus();
    strOut.append("Response Status Code = ");
    strOut.appendInt(respStatusCode);
    strOut.append("\r\n");
    if (respStatusCode >= 400) {
        strOut.append("Response Header:");
        strOut.append("\r\n");
        strOut.append(http.lastHeader());
        strOut.append("\r\n");
        strOut.append("Failed.");
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // [
    //   {
    //     "id": 1902,
    //     "date": "2020-11-16T09:54:09",
    //     "date_gmt": "2020-11-16T16:54:09",
    //     "guid": {
    //       "rendered": "http:\/\/cknotes.com\/?p=1902"
    //     },
    //     "modified": "2020-11-16T09:54:09",
    //     "modified_gmt": "2020-11-16T16:54:09",
    //     "slug": "xero-redirect-uri-for-oauth2-and-desktop-apps",
    //     "status": "publish",
    //     "type": "post",
    //     "link": "https:\/\/cknotes.com\/xero-redirect-uri-for-oauth2-and-desktop-apps\/",
    //     "title": {
    //       "rendered": "Xero Redirect URI for OAuth2 and Desktop Apps"
    //     },
    //     "content": {
    //       "rendered": "<p>...",
    //       "protected": false
    //     },
    //     "excerpt": {
    //       "rendered": "<p>...",
    //       "protected": false
    //     },
    //     "author": 1,
    //     "featured_media": 0,
    //     "comment_status": "closed",
    //     "ping_status": "open",
    //     "sticky": false,
    //     "template": "",
    //     "format": "standard",
    //     "meta": [
    //     ],
    //     "categories": [
    //       815
    //     ],
    //     "tags": [
    //       594,
    //       816
    //     ],
    //     "_links": {
    //       "self": [
    //         {
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902"
    //         }
    //       ],
    //       "collection": [
    //         {
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts"
    //         }
    //       ],
    //       "about": [
    //         {
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/post"
    //         }
    //       ],
    //       "author": [
    //         {
    //           "embeddable": true,
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1"
    //         }
    //       ],
    //       "replies": [
    //         {
    //           "embeddable": true,
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=1902"
    //         }
    //       ],
    //       "version-history": [
    //         {
    //           "count": 1,
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902\/revisions"
    //         }
    //       ],
    //       "predecessor-version": [
    //         {
    //           "id": 1904,
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902\/revisions\/1904"
    //         }
    //       ],
    //       "wp:attachment": [
    //         {
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media?parent=1902"
    //         }
    //       ],
    //       "wp:term": [
    //         {
    //           "taxonomy": "category",
    //           "embeddable": true,
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/categories?post=1902"
    //         },
    //         {
    //           "taxonomy": "post_tag",
    //           "embeddable": true,
    //           "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/tags?post=1902"
    //         }
    //       ],
    //       "curies": [
    //         {
    //           "name": "wp",
    //           "href": "https:\/\/api.w.org\/{rel}",
    //           "templated": true
    //         }
    //       ]
    //     }
    //   },
    // ...
    // ]

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    CkDtObj date_gmt;
    CkJsonObject *json = 0;
    int id;
    const char *date = 0;
    const char *guidRendered = 0;
    const char *modified = 0;
    const char *modified_gmt = 0;
    const char *slug = 0;
    const char *status = 0;
    const char *v_type = 0;
    const char *link = 0;
    const char *titleRendered = 0;
    const char *contentRendered = 0;
    bool contentProtected;
    const char *excerptRendered = 0;
    bool excerptProtected;
    int author;
    int featured_media;
    const char *comment_status = 0;
    const char *ping_status = 0;
    bool sticky;
    const char *template = 0;
    const char *format = 0;
    int j;
    int count_j;
    int intVal;
    const char *href = 0;
    bool embeddable;
    int count;
    const char *taxonomy = 0;
    const char *name = 0;
    bool templated;

    int i = 0;
    int count_i = jarrResp.get_Size();
    while (i < count_i) {
        json = jarrResp.ObjectAt(i);
        id = json->IntOf("id");
        date = json->stringOf("date");
        json->DtOf("date_gmt",false,date_gmt);
        guidRendered = json->stringOf("guid.rendered");
        modified = json->stringOf("modified");
        modified_gmt = json->stringOf("modified_gmt");
        slug = json->stringOf("slug");
        status = json->stringOf("status");
        v_type = json->stringOf("type");
        link = json->stringOf("link");
        titleRendered = json->stringOf("title.rendered");
        contentRendered = json->stringOf("content.rendered");
        contentProtected = json->BoolOf("content.protected");
        excerptRendered = json->stringOf("excerpt.rendered");
        excerptProtected = json->BoolOf("excerpt.protected");
        author = json->IntOf("author");
        featured_media = json->IntOf("featured_media");
        comment_status = json->stringOf("comment_status");
        ping_status = json->stringOf("ping_status");
        sticky = json->BoolOf("sticky");
        template = json->stringOf("template");
        format = json->stringOf("format");
        j = 0;
        count_j = json->SizeOfArray("meta");
        while (j < count_j) {
            json->put_J(j);
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("categories");
        while (j < count_j) {
            json->put_J(j);
            intVal = json->IntOf("categories[j]");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("tags");
        while (j < count_j) {
            json->put_J(j);
            intVal = json->IntOf("tags[j]");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.self");
        while (j < count_j) {
            json->put_J(j);
            href = json->stringOf("_links.self[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.collection");
        while (j < count_j) {
            json->put_J(j);
            href = json->stringOf("_links.collection[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.about");
        while (j < count_j) {
            json->put_J(j);
            href = json->stringOf("_links.about[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.author");
        while (j < count_j) {
            json->put_J(j);
            embeddable = json->BoolOf("_links.author[j].embeddable");
            href = json->stringOf("_links.author[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.replies");
        while (j < count_j) {
            json->put_J(j);
            embeddable = json->BoolOf("_links.replies[j].embeddable");
            href = json->stringOf("_links.replies[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.version-history");
        while (j < count_j) {
            json->put_J(j);
            count = json->IntOf("_links.version-history[j].count");
            href = json->stringOf("_links.version-history[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.predecessor-version");
        while (j < count_j) {
            json->put_J(j);
            id = json->IntOf("_links.predecessor-version[j].id");
            href = json->stringOf("_links.predecessor-version[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.wp:attachment");
        while (j < count_j) {
            json->put_J(j);
            href = json->stringOf("_links.wp:attachment[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.wp:term");
        while (j < count_j) {
            json->put_J(j);
            taxonomy = json->stringOf("_links.wp:term[j].taxonomy");
            embeddable = json->BoolOf("_links.wp:term[j].embeddable");
            href = json->stringOf("_links.wp:term[j].href");
            j = j + 1;
        }

        j = 0;
        count_j = json->SizeOfArray("_links.curies");
        while (j < count_j) {
            json->put_J(j);
            name = json->stringOf("_links.curies[j].name");
            href = json->stringOf("_links.curies[j].href");
            templated = json->BoolOf("_links.curies[j].templated");
            j = j + 1;
        }

        delete json;
        i = i + 1;
    }



    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

    }

 

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