Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) RSAP Union API - Get Members StatusDemonstrates how to use an OAuth2 access token for the RSAP Union API. Calls the endpoint to get the statuses of all union members. For more information, see https://app.swaggerhub.com/apis-docs/pderas/RSAP/2.0.1#/Members/getAllUnionMemberStatuses
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkCertW.h> #include <C_CkPrivateKeyW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW jToken; HCkCertW cert; HCkPrivateKeyW privKey; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Load the access token previously obtained by this example: RSAP Union OAuth2 jToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jToken,L"qa_data/tokens/rsapToken.json"); if (success == FALSE) { wprintf(L"Failed to load access token JSON.\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); return; } // Adds the "Authorization: Bearer ACCESS_TOKEN" header. CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jToken,L"access_token")); // For authentication, assuming both the client cert and access token are needed??? cert = CkCertW_Create(); success = CkCertW_LoadFromFile(cert,L"qa_data/certs_and_keys/union_client_certificate.crt"); if (success == FALSE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); return; } privKey = CkPrivateKeyW_Create(); success = CkPrivateKeyW_LoadAnyFormatFile(privKey,L"qa_data/certs_and_keys/union_client_certificate.nopass.key",L""); if (success == FALSE) { wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); CkPrivateKeyW_Dispose(privKey); return; } // Associate the private key with the cert. // This will fail if the private key is not actually the correct one that corresponds to the public key stored within the cert. success = CkCertW_SetPrivateKey(cert,privKey); if (success == FALSE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); CkPrivateKeyW_Dispose(privKey); return; } // Tell HTTP to use the cert for client TLS certificate authentication. success = CkHttpW_SetSslClientCert(http,cert); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); CkPrivateKeyW_Dispose(privKey); return; } sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://api-test.rsap.ca/members/status",sbResponseBody); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); CkPrivateKeyW_Dispose(privKey); CkStringBuilderW_Dispose(sbResponseBody); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); CkPrivateKeyW_Dispose(privKey); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jToken); CkCertW_Dispose(cert); CkPrivateKeyW_Dispose(privKey); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.