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++) MedTunnel: Send Message Text OnlySee more MedTunnel ExamplesDemonstrates the MedTunnel SendMessage method to send a message to one or more recipients. For more information, see https://server.medtunnel.com/apidocs/html/M_MedTunnelMsg_Controllers_MessageController_SendMessage.htm
#include <CkHttpW.h> #include <CkHttpRequestW.h> #include <CkHttpResponseW.h> #include <CkStringBuilderW.h> #include <CkJsonObjectW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; bool success; // Implements the following CURL command: // curl https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage -X POST -k // -F "ApplicationId=yourApplicationId" -F "LocationId=yourLocationId" // -F "MedTunnelId=yourMedTunnelId" -F "MedTunnelPassword=yourMedTunnelPassword" // -F "To=recipientsMedTunnelId" // -F "Body=Test of SendMessage" // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code CkHttpRequestW req; req.put_HttpVerb(L"POST"); req.put_Path(L"/MedTunnelMsg/api/Message/SendMessage"); req.put_ContentType(L"multipart/form-data"); req.AddParam(L"ApplicationId",L"yourApplicationId"); req.AddParam(L"LocationId",L"yourLocationId"); req.AddParam(L"MedTunnelId",L"yourMedTunnelId"); req.AddParam(L"MedTunnelPassword",L"yourMedTunnelPassword"); req.AddParam(L"To",L"recipientsMedTunnelId"); req.AddParam(L"Body",L"Test"); CkHttpResponseW *resp = http.SynchronousRequest(L"server.medtunnel.com",443,true,req); if (http.get_LastMethodSuccess() == false) { wprintf(L"%s\n",http.lastErrorText()); return; } CkStringBuilderW sbResponseBody; resp->GetBodySb(sbResponseBody); CkJsonObjectW jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); wprintf(L"Response Body:\n"); wprintf(L"%s\n",jResp.emit()); int respStatusCode = resp->get_StatusCode(); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",resp->header()); wprintf(L"Failed.\n"); delete resp; return; } delete resp; // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "ReturnCode": 1, // "ReturnCodeText": "Success", // "Data": "{\"Id\":989432,\"FromUserId\":36990,\"FromMailBoxId\":36965, ... \"SendGlobalNotifications\":false}" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON int ReturnCode = jResp.IntOf(L"ReturnCode"); const wchar_t *ReturnCodeText = jResp.stringOf(L"ReturnCodeText"); const wchar_t *Data = jResp.stringOf(L"Data"); // Load the Data into another JSON object and parse.. CkJsonObjectW jsonData; jsonData.Load(Data); jsonData.put_EmitCompact(false); wprintf(L"%s\n",jsonData.emit()); // { // "Id": 989436, // "FromUserId": 36990, // "FromMailBoxId": 36965, // "FromUserType": 0, // "FromUserName": "...", // "FromUserFullName": "...", // "FromUserAccountName": "...", // "FromUserAccountTitle": "...", // "ToUserId": 36990, // "ToUserType": 1, // "ToUserMailboxId": "36965", // "ToUserName": "...", // "ToUserFullName": "...", // "EmailAddress": "", // "Password": "", // "Subject": "", // "PatientMedTunnelId": "", // "Body": "Test", // "DateReceived": "4/29/2021 2:29:18 PM", // "DisplayDateReceived": "04/29/2021 2:29 PM", // "ViewCount": 0, // "ViewedOn": "", // "AttachmentCount": 0, // "AttachmentNames": [ // ], // "AllRecipients": [ // { // "Id": 989436, // "UserName": "...", // "AccountId": 0, // "AccountName": "...", // "AccountTitle": "", // "FirstName": "...", // "LastName": "...", // "EmailAddress": "", // "LastSentOn": "", // "SendCount": 0, // "IsFavorite": false // } // ], // "Status": 1, // "ParentMessageId": 989436, // "DistributionListId": 0, // "DistributionListName": "", // "BodyHistory": "", // "ReadReceiptCallbackUrl": null, // "SendGlobalNotifications": false // } // // 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. const wchar_t *UserName = 0; int AccountId; const wchar_t *AccountName = 0; const wchar_t *AccountTitle = 0; const wchar_t *FirstName = 0; const wchar_t *LastName = 0; const wchar_t *LastSentOn = 0; int SendCount; bool IsFavorite; int Id = jsonData.IntOf(L"Id"); int FromUserId = jsonData.IntOf(L"FromUserId"); int FromMailBoxId = jsonData.IntOf(L"FromMailBoxId"); int FromUserType = jsonData.IntOf(L"FromUserType"); const wchar_t *FromUserName = jsonData.stringOf(L"FromUserName"); const wchar_t *FromUserFullName = jsonData.stringOf(L"FromUserFullName"); const wchar_t *FromUserAccountName = jsonData.stringOf(L"FromUserAccountName"); const wchar_t *FromUserAccountTitle = jsonData.stringOf(L"FromUserAccountTitle"); int ToUserId = jsonData.IntOf(L"ToUserId"); int ToUserType = jsonData.IntOf(L"ToUserType"); const wchar_t *ToUserMailboxId = jsonData.stringOf(L"ToUserMailboxId"); const wchar_t *ToUserName = jsonData.stringOf(L"ToUserName"); const wchar_t *ToUserFullName = jsonData.stringOf(L"ToUserFullName"); const wchar_t *EmailAddress = jsonData.stringOf(L"EmailAddress"); const wchar_t *Password = jsonData.stringOf(L"Password"); const wchar_t *Subject = jsonData.stringOf(L"Subject"); const wchar_t *PatientMedTunnelId = jsonData.stringOf(L"PatientMedTunnelId"); const wchar_t *Body = jsonData.stringOf(L"Body"); const wchar_t *DateReceived = jsonData.stringOf(L"DateReceived"); const wchar_t *DisplayDateReceived = jsonData.stringOf(L"DisplayDateReceived"); int ViewCount = jsonData.IntOf(L"ViewCount"); const wchar_t *ViewedOn = jsonData.stringOf(L"ViewedOn"); int AttachmentCount = jsonData.IntOf(L"AttachmentCount"); int Status = jsonData.IntOf(L"Status"); int ParentMessageId = jsonData.IntOf(L"ParentMessageId"); int DistributionListId = jsonData.IntOf(L"DistributionListId"); const wchar_t *DistributionListName = jsonData.stringOf(L"DistributionListName"); const wchar_t *BodyHistory = jsonData.stringOf(L"BodyHistory"); const wchar_t *ReadReceiptCallbackUrl = jsonData.stringOf(L"ReadReceiptCallbackUrl"); bool SendGlobalNotifications = jsonData.BoolOf(L"SendGlobalNotifications"); int i = 0; int count_i = jsonData.SizeOfArray(L"AttachmentNames"); while (i < count_i) { jsonData.put_I(i); i = i + 1; } i = 0; count_i = jsonData.SizeOfArray(L"AllRecipients"); while (i < count_i) { jsonData.put_I(i); Id = jsonData.IntOf(L"AllRecipients[i].Id"); UserName = jsonData.stringOf(L"AllRecipients[i].UserName"); AccountId = jsonData.IntOf(L"AllRecipients[i].AccountId"); AccountName = jsonData.stringOf(L"AllRecipients[i].AccountName"); AccountTitle = jsonData.stringOf(L"AllRecipients[i].AccountTitle"); FirstName = jsonData.stringOf(L"AllRecipients[i].FirstName"); LastName = jsonData.stringOf(L"AllRecipients[i].LastName"); EmailAddress = jsonData.stringOf(L"AllRecipients[i].EmailAddress"); LastSentOn = jsonData.stringOf(L"AllRecipients[i].LastSentOn"); SendCount = jsonData.IntOf(L"AllRecipients[i].SendCount"); IsFavorite = jsonData.BoolOf(L"AllRecipients[i].IsFavorite"); i = i + 1; } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.