Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with doing an http post with data
#1
Looking for a clue here ... I'm trying duplicate the curl command below with CML. It kinda works, but the Data isn't getting passed. I have a feeling I'm using the SendPost method incorrectly. Any thoughts?

Code:
curl -X POST -H "Content-Type: application/json" -d '{"value1":"a","value2":"b","value3":"c"}' https://maker.ifttt.com/trigger/cqc_notify/with/key/cf_8ZeO4rVrss2VmyFty4f


    Method runMe([Out] String RetCode) Returns Int4    Begin
        Locals=
            LinesList   OutHdrLines;
            LinesList   InHdrLines;
            LinesList   PostVals;
            URL         URLobject;
            String      RepText;
            String      ContType;
            MemBuf      DataBuf;
            Card4       ContLen;
            Card4       ResCode;
            String      URLStr;
            String      Data;
        EndLocals;

        Data := "{\"value1\":\"a\",\"value2\":\"b\",\"value3\":\"c\"}";

        URLStr := "https://maker.ifttt.com/trigger/cqc_notify/with/key/dfg43fg34";
        ContType := "application/json";

        m_XCoder.ConvertTo(Data, DataBuf, ContLen);

        Try
            URLobject.Set(URLStr, FQTypes.Full);

            //ContLen := 0;

            ResCode := m_HTTP.SendPOST(URLobject, 5000, "myAgent", "*/*", PostVals
                , RepText, OutHdrLines, ContType, DataBuf, ContLen
                 , InHdrLines);

            RetCode.Clear();
            RetCode.AppendCard4(ResCode, Radices.Dec);
        EndTry;

        Catch
            Return 0;
        EndCatch;

        Return 1;
    EndMethod;
--Kill all the serial ports--
Reply
#2
There's another POST variant that will make it easier and make sure it gets done right. It takes the post values as a set of key/value pairs. Try using that one.
Dean Roddey
Explorans limites defectum
Reply
#3
AhhHH!HH!!!!
It worked first try. Why didn't I ask sooner?

Thanks.
Code:
ResCode := m_HTTP.SendPOST2(URLobject, 5000, "CQC", "*/*", RepText,
              OutHdrLines,ContType, DataBuf, ContLen, True, InHdrLines);
--Kill all the serial ports--
Reply
#4
whatcha doin'?
do the needful ...
Hue | Sonos | Harmony | Elk M1G // Netatmo / Brultech
Reply
#5
Can i get please whole code of this macro - i getting error: class LinesList was not found.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Curious About Usage Post Public Domain kblagron 17 1,631 09-24-2021, 09:00 AM
Last Post: Dean Roddey
  Get Field Value via HTTP znelbok 3 1,165 06-11-2020, 03:43 PM
Last Post: Dean Roddey
  HTTP Trigger and Parameters znelbok 1 900 06-11-2020, 03:41 PM
Last Post: Dean Roddey
  V2 Question - OpenWeatherMap Using their New JSON Data Feed kblagron 7 2,038 05-07-2020, 01:40 PM
Last Post: Dean Roddey
  HTTP SendPUT simplextech 3 1,456 01-21-2020, 03:05 PM
Last Post: simplextech
  CQC HTTP Events? bjkiller 26 8,419 01-11-2020, 07:27 AM
Last Post: simplextech
  Set value via HTTP Call simplextech 2 1,178 01-07-2020, 04:39 PM
Last Post: simplextech
  HTTP Trigger Driver - see trained URL's? Shaky 1 1,611 09-15-2019, 12:25 PM
Last Post: Dean Roddey
  HTTP Get driver not working znelbok 10 5,236 08-28-2018, 10:10 AM
Last Post: Dean Roddey
  Http Post zra 17 6,865 08-05-2018, 01:55 PM
Last Post: zra

Forum Jump:


Users browsing this thread: 1 Guest(s)