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) HTTP GET with Custom Header and OAuth2 Bearer TokenSee more HTTP ExamplesDemonstrate how to send a GET request with customer headers and an "Authorization: Bearer
#include <C_CkHttpW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { BOOL success; HCkHttpW http; const wchar_t *url; HCkStringBuilderW sb; HCkJsonObjectW json; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Setting the AuthToken property causes the "Authorization: Bearer <token>" header to be adeded. CkHttpW_putAuthToken(http,L"Just_the_access_token_here"); // Add one or more custom headers.. CkHttpW_SetRequestHeader(http,L"X-Tenant-ID",L"value goes here"); CkHttpW_SetRequestHeader(http,L"blah-blah-blah",L"value goes here"); url = L"https://www.example.com/abc/123?x=something&y=someOtherThing"; // Send the GET request and get the response body in the StringBuilder object. sb = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,url,sb); if (success != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sb); return; } wprintf(L"response status code: %d\n",CkHttpW_getLastStatus(http)); wprintf(L"response body:\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sb)); // If the response contains JSON, you can load it into a Chilkat JSON object... json = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(json,sb); CkJsonObjectW_putEmitCompact(json,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(json)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sb); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.