![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Example: Http.HttpReq methodDemonstrates how to call the HttpReq method. Note: This example requires Chilkat v11.0.0 or greater.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoHttp Handle hoJson Variant vReq Handle hoReq Variant vResp Handle hoResp String sTemp1 Move False To iSuccess Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Move False To iSuccess // This example will send an HTTP POST with the body of the HTTP request containing JSON. // Create the following JSON: { "name": "Harry", "state": "FL" } Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "name" "Harry" To iSuccess Get ComUpdateString Of hoJson "state" "FL" To iSuccess // Specify the details of the request Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Set ComHttpVerb Of hoReq To "POST" Set ComContentType Of hoReq To "application/json" Get ComEmit Of hoJson To sTemp1 Get ComLoadBodyFromString Of hoReq sTemp1 "utf-8" To iSuccess // Send the charset attribute in the HTTP request header. Set ComSendCharset Of hoReq To True Set ComCharset Of hoReq To "utf-8" // Send the POST // You can send the POST to the URL below. // The response will contain the raw body of the request that was sent. // (i.e. everything except the HTTP request header). Get Create (RefClass(cComChilkatHttpResponse)) To hoResp If (Not(IsComObjectCreated(hoResp))) Begin Send CreateComObject of hoResp End Get pvComObject of hoReq to vReq Get pvComObject of hoResp to vResp Get ComHttpReq Of hoHttp "https://www.chilkatsoft.com/echo_request_body.asp" vReq vResp To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End // Examine the HTTP request header we sent: Get ComLastHeader Of hoHttp To sTemp1 Showln sTemp1 // The response body contains the raw content of the HTTP request body we sent. Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 // Sample output: // POST /echo_request_body.asp HTTP/1.1 // Host: www.chilkatsoft.com // Content-Type: application/json; charset=utf-8 // Content-Length: 29 // // // {"name":"Harry","state":"FL"} End_Procedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.