Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 18:37:18 +0000



Sending requests to a server

View Count: 2543

[2018-12-17 16:22:54]
User974747 - Posts: 4
Hi Tech Engineering Support

I am trying to create a script (custom study) that needs to make http POST request to a server. In docs i found a function - "MakeHTTPRequest" by seems it can send only GET requests. But what if need to send POST requests with custom headers? I tried to use a external library like cpr or curl, but I can't seem to include them to the script, is this support? Please let me know how to proceed in making http POST request in my script.
[2018-12-17 22:04:14]
Sierra Chart Engineering - Posts: 104368
This function will be added to the next release:

sc.MakeHTTPPOSTRequest(const SCString& URL, const char* POSTData)

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-12-17 22:04:25
[2018-12-18 15:01:06]
User974747 - Posts: 4
Thanks for the response. When approximately you are going to release? And will that function support headers or only URL and POST body data ?
[2018-12-19 03:58:54]
Sierra Chart Engineering - Posts: 104368
This has now been released in version 1852. It is now out. It just supports the POST data. You cannot set headers. Do you need to set headers?
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-12-19 11:29:13]
User12089 - Posts: 361
does a call to the function block the main thread of execution of SC? that's to say, is the call to the function synchronous or asynchronous ?
[2018-12-19 15:45:21]
User974747 - Posts: 4
Yes i need to use headers. I need to send authorized POST request with header like:
Authorization: Bearer <token>
[2018-12-19 17:44:55]
Sierra Chart Engineering - Posts: 104368
It is asynchronous.

We will see about adding support for a header.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-12-19 17:45:04
[2018-12-20 08:32:23]
User974747 - Posts: 4
Hi. Can you also add


sc.MakeHTTPPOSTRequest(const SCString& URL, const char* POSTData)

to the documentation to see how to use it ?
[2018-12-20 22:37:10]
Sierra Chart Engineering - Posts: 104368
You need to wait for release 1853 and this is the code example:

SCSFExport scsf_HTTPTestWithPOST(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults

    sc.GraphName = "HTTP Request Test with POST";

    sc.StudyDescription = "This is a study function that demonstrates how to request data from a web server.";

    sc.AutoLoop = 0;
    return;
  }

  int& RequestState = sc.GetPersistentInt(1);

  // Do data processing

  if (sc.UpdateStartIndex == 0 && sc.IsFullRecalculation)
  {
    if (RequestState == HTTP_REQUEST_ERROR || RequestState == HTTP_REQUEST_RECEIVED)
    {
      n_ACSIL::s_HTTPHeader HTTPHeader;
      HTTPHeader.Name = "Custom";
      HTTPHeader.Value = "Value";

      // Make a request to the server.
      // When the request is complete and all of the data has been downloaded,
      //this study function will be called with the file placed into the sc.HTTPResponse character string array.
      if (!sc.MakeHTTPPOSTRequest("https://www.sierrachart.com/Test/ACSILPOSTTest.php", "Message=PostData", &HTTPHeader, 1))
      {
        sc.AddMessageToLog("Error making HTTP request.", 1);
      }

      RequestState = HTTP_REQUEST_MADE;
    }
  }

  if (RequestState == HTTP_REQUEST_MADE && sc.HTTPRequestID != 0)
  {
    RequestState = HTTP_REQUEST_RECEIVED;

    // Display the response from the Web server in the Message Log
    sc.AddMessageToLog(sc.HTTPResponse, 1);
  }
}

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-12-20 22:40:25
[2019-04-30 23:45:06]
uM8137 - Posts: 183
MakeHTTPPOSTRequest is very nice and useful functionality.

There is a small bug in it that does limit its utility quite a bit. The function ignores the port provided in the URL, and always attempts to post on port 80. For example, the URL "http://127.0.0.1:9090/hello" will ignore the port 9090 request, and try to bind 127.0.0.1:80 instead. Since low ports like 80 are reserved for superuser typically, and often in use for other purposes, this is suboptimal.
[2019-05-01 02:32:08]
Sierra Chart Engineering - Posts: 104368
This is not a bug. This is just simply a limitation. It is not something we can spend any time changing now. We also recommend a secure connection using 443.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2019-05-01 02:32:19
[2019-05-01 08:25:53]
uM8137 - Posts: 183
> We also recommend a secure connection using 443.

This seemed like a good idea. So I tried it. Just fyi, this is also "limited" at the moment. Using a URL starting with 'https://', the protocol is ignored. It still uses port 80, and it doesn't speak TLS, just raw http.

I'd rather do gRPC anyway, so I'll try that. Don't worry about trying to patch this dumpster fire. It should probably just be replaced with libcurl anyway. (https://curl.haxx.se; free, mature, knows how to parse URLs and do https; is MIT licensed).
[2020-11-27 19:35:58]
kam2001 - Posts: 79
Can json/Application Headers be sent with this request as currently it sends application/x-www-form-urlencoded headers only, if trying to specify json header in current version it breaks with SyntaxError: Unexpected token < in JSON at position - Thanks
[2023-05-31 00:42:10]
@sstfrederik - Posts: 404
Is there be support for the use of multiple headers?
[2023-05-31 07:20:52]
Sierra_Chart Engineering - Posts: 17182
Yes this function supports multiple headers:
int (SCDLLCALL* MakeHTTPPOSTRequest)(const SCString& URL, const SCString& POSTData, const n_ACSIL::s_HTTPHeader* Headers, int NumberOfHeaders);

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-06-01 23:50:38]
@sstfrederik - Posts: 404
thanks I understand and have that working. Would it be possible to have a MakeHTTPPOSTRequest function that supports a mix of text and binary data in the POSTData payload? In my experience sending binary image data is not possible with the current function.
[2023-06-02 09:56:59]
Sierra_Chart Engineering - Posts: 17182
Not really sure about this. It is too involved for us to be looking into this now.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2023-06-02 11:45:03
[2023-06-02 22:16:38]
@sstfrederik - Posts: 404
Thanks. Seems I no longer need this as I can get away with base64 encoding.
[2023-11-08 22:14:09]
User191221 - Posts: 2
hi there I'm getting this massage its says (making HTTP request) with custom study
thank you
[2023-11-08 22:14:09]
User191221 - Posts: 2
hi there I'm getting this massage its says (making HTTP request) with custom study
thank you
[2023-11-09 03:13:59]
Sierra_Chart Engineering - Posts: 17182
It is the custom study doing that. If you do not want that to occur, then remove the custom study from your charts.

You can do this through Analysis >> Studies for each chart.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account