Support Board
Date/Time: Wed, 12 Mar 2025 21:17:16 +0000
HTTPPOST always returns empty response (confirmed that HTTPResponse from server is non-empty)
View Count: 611
[2022-05-19 13:09:21] |
ray42 - Posts: 21 |
Hi, I'm trying to encode a string like param=123¶m2=abc def¶m3=chart #1 into a valid URL like following: param=123¶m2=abc+def¶m3=chart+%231
I did not find any sc.* functions to achieve this so I found a few URL encode methods for C++ (source: https://stackoverflow.com/questions/154536/encode-decode-urls-in-c, https://gist.github.com/litefeel/1197e5c24eb9ec93d771) But none of these methods work as the printed string is just random characaters. #include <cctype>
#include <iomanip> #include <sstream> #include <string> string url_encode(const string &value) { ostringstream escaped; escaped.fill('0'); escaped << hex; for (string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) { string::value_type c = (*i); // Keep alphanumeric and other accepted characters intact if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { escaped << c; continue; } // Any other characters are percent-encoded escaped << uppercase; escaped << '%' << setw(2) << int((unsigned char) c); escaped << nouppercase; } return escaped.str(); } SCSFExport scsf_samplecode(SCStudyInterfaceRef sc){ if (sc.SetDefaults){ ... } SCString PostMessage = "param=123¶m2=abc def¶m3=chart #1"; sc.AddMessageToLog(PostMessage, 0); SCString PostMessagEnc; PostMessagEnc.Format("%s", url_encode(PostMessage.GetChars())); sc.AddMessageToLog(PostMessagEnc, 0); } Can someone please help with a solution for this? Edit: Please ignore this - I have found a solution based on another thread and have posted it as a comment, but I'm not able to see HTTP responses. Date Time Of Last Edit: 2022-05-19 15:34:38
|
![]() |
[2022-05-19 15:33:01] |
ray42 - Posts: 21 |
Solved by using `sc.MakeHTTPPOSTRequest` and handling the post data string in the backend appropriately. This thread helped: https://www.sierrachart.com/SupportBoard.php?ThreadID=58501 However, I'm still not able to see the response from the server. Engineering Team, can you please help with this? Also, saw this thread: sc.HTTPResponse always empty. I tried printing out the HTTPResponse in other parts of the code, still, I'm not able to see anything on the output log. |
To post a message in this thread, you need to log in with your Sierra Chart account: