Support Board
Date/Time: Thu, 10 Oct 2024 01:42:48 +0000
Post From: Control Bar Buttons Using Http Request Crashing Sierra Chart
[2022-10-03 04:38:36] |
kam2001 - Posts: 79 |
Hi, i am trying to make http post request when a button is clicked but for some reason Sierra Chart is shutting (crashing) down, it's definately the code used for sc.MakeHTTPPOSTRequest as i can display the message in the log if i don't use sc.MakeHTTPPOSTRequest. But this exact code for sc.MakeHTTPPOSTRequest works in my other study on the chart. Any Suggestions!!. Thanks #include "sierrachart.h"
#include <iostream> #include <string.h> #include <sstream> SCDLLName("MyToolbarButton") void PassingSCStrutureExampleFunction(SCStudyInterfaceRef sc) { } SCSFExport scsf_MyToolBarButton(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "MY ToolBar Button"; sc.StudyDescription = "This code does something"; sc.GraphRegion = 0; sc.AutoLoop = 0; sc.Input[0].Name = "Post"; sc.Input[0].SetInt(0); return; } if (sc.IsFullRecalculation) { sc.SetCustomStudyControlBarButtonHoverText(ACS_BUTTON_1, "CLICK"); sc.SetCustomStudyControlBarButtonText(ACS_BUTTON_1, "CLICK"); } enum { REQUEST_NOT_SENT = 0, REQUEST_SENT, REQUEST_RECEIVED }; int& RequestState = sc.GetPersistentInt(1); n_ACSIL::s_HTTPHeader HTTPHeader; HTTPHeader.Name = "Some-Header"; HTTPHeader.Value = "123"; int NumberOfHeaders = 2; int postData = sc.Input[0].GetInt(); const char* APIURL = "http://localhost:9000/demo"; std::string test; SCDateTime SysTime = sc.CurrentSystemDateTime; SCString MessageText; // wait for a button if (sc.MenuEventID == ACS_BUTTON_1 && postData > 0) { if (sc.PointerEventType == SC_ACS_BUTTON_ON) { MessageText.AppendFormat("Clicked Now %i, ", sc.MenuEventID); sc.AddMessageToLog(MessageText, 0); test = "SOMEVALUE"; std::string str = "&test=" + test const char *cstr = str.c_str(); if (!sc.MakeHTTPPOSTRequest(APIURL, cstr, &HTTPHeader, NumberOfHeaders)) { sc.AddMessageToLog("Error making HTTP request.", 1); RequestState = REQUEST_NOT_SENT; } else { sc.AddMessageToLog(APIURL, 1); sc.AddMessageToLog("BUY HTTP request Made.", 1); RequestState = REQUEST_SENT; } // reset button to off sc.SetCustomStudyControlBarButtonEnable(sc.MenuEventID, 0); } else if (sc.PointerEventType == SC_ACS_BUTTON_OFF){ sc.AddMessageToLog("ACS Button Off Event.", 1); } sc.SetCustomStudyControlBarButtonEnable(sc.PriorSelectedCustomStudyControlBarButtonNumber, 0); } } Date Time Of Last Edit: 2022-10-03 04:40:39
|