Support Board
Date/Time: Fri, 20 Sep 2024 12:59:48 +0000
[Programming Help] - Control Bar Buttons Using Http Request Crashing Sierra Chart
View Count: 1006
[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
|
[2022-10-03 07:06:17] |
User431178 - Posts: 505 |
Probably memory access violation when reading Headers, although I'm guessing slightly as the function is not documented. int MakeHTTPPOSTRequest(const SCString& URL, const SCString& POSTData, const n_ACSIL::s_HTTPHeader* Headers, int NumberOfHeaders); I'd expect the Headers parameter to be the address of an array of headers, which is why the NumberOfHeaders parameter is needed. In your code you pass the address of a single header, but you tell the function that there are 2 headers to read, when the second non-existant header is read an access violation can occur. Suggest setting NumberOfHeaders = 1 If you actually need 2 headers then const int numberOfHeaders = 2 n_ACSIL::s_HTTPHeader HTTPHeaders[numberOfHeaders]; HTTPHeaders[0].Name = "Some-Header"; HTTPHeaders[0].Value = "123"; HTTPHeaders[1].Name = "Some-Other-Header"; HTTPHeaders[1].Value = "456"; |
[2022-10-03 09:59:28] |
kam2001 - Posts: 79 |
I tried changing the number of headers (but it worked in my other study regardless different no of header defined) anyway and i also commented out the code below - and one of the trick did the job not sure which one though. Thanks anyway. //#include <iostream> //#include <string.h> //#include <sstream> |
To post a message in this thread, you need to log in with your Sierra Chart account: