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) Demonstrate the REST FullRequestNoBodySb MethodSee more REST ExamplesDemonstrates the FullRequestNoBodySb method, which sends an HTTP request with no body and receives the response in a Chilkat StringBuilder object.
#include <C_CkRestW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkRestW rest; BOOL bTls; int port; BOOL bAutoReconnect; BOOL success; HCkStringBuilderW sbJson; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rest = CkRestW_Create(); // Connect to the REST server. bTls = TRUE; port = 443; bAutoReconnect = TRUE; success = CkRestW_Connect(rest,L"chilkatsoft.com",port,bTls,bAutoReconnect); if (success == FALSE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkRestW_Dispose(rest); return; } // Send an HTTP request with no body... // An HTTP request with no body is a simple HTTP request that is typically a GET or DELETE. // (POST and PUT requests typically have a request body.) // The GET method is used to request data from a specified resource, // and it does not have a request body. Here's an example of an HTTP GET request: // // GET /api/data HTTP/1.1 // Host: example.com // Accept: application/json // // - The HTTP method (also known as the verb) is "GET," indicating that the client wants to retrieve data from the specified resource. // - The request path is "/api/data," representing the resource the client wants to access. // - The "Host" header specifies the hostname of the server being requested. Chilkat automatically adds it. // - The "Accept" header indicates the media type (MIME type) that the client can understand and would like to receive in the response. In this case, it specifies that the client prefers to receive data in JSON format. // // Since the GET method does not have a request body, the request ends after the headers. // The server will process the request, retrieve the requested data (if available), and respond with an HTTP response // containing the requested data (if any) in the message body. // // The body of the HTTP response is written to the StringBuilder object (overwriting whatever content the StringBuilder may have already contained). // CkRestW_AddHeader(rest,L"Accept",L"application/json"); sbJson = CkStringBuilderW_Create(); success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/testData/helloWorld.json",sbJson); if (success == FALSE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkRestW_Dispose(rest); CkStringBuilderW_Dispose(sbJson); return; } wprintf(L"Response status code = %d\n",CkRestW_getResponseStatusCode(rest)); wprintf(L"Response body:\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson)); CkRestW_Dispose(rest); CkStringBuilderW_Dispose(sbJson); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.