Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTP SendPUT
#1
I'm looking through the reference documentation on the SendPUT.

Code:
SendPUT
(
    [In]    MEng.System.Runtime.URL URL
    , [In]  MEng.Card4 WaitFor
    , [In]  MEng.String Agent
    , [In]  MEng.String Accept
    , [Out] MEng.String RepText
    , [Out] MEng.System.Runtime.HTTPClient.LinesList OutHdrLines
    , [InOu MEng.String ContType
    , [InOu MEng.System.Runtime.MemBuf Content
    , [InOu MEng.Card4 ContLen
    , [In]  MEng.Boolean OutBody
    , [In]  MEng.System.Runtime.HTTPClient.LinesList InHdrLines
)   Returns MEng.Card4;

I'm guessing the MEng.System.Runtime.MemBuf is the Body of the message (outbound) for the PUT?  This is a memory buffer and I was looking at the docs for that.  I'm not sure what would be correct for adding a JSON string to this.  Anyone know?  I'm trying to write a Macro to send a PUT to the Hue bridge to turn on/off Hue groups.
Reply
#2
Sorta crude but it functions.  I need to add input fields for use with actions instead of hard coded values.  But the macro works.

Code:
Class=[NonFinal]
    ClassPath MEng.User.DoHTTPPut;
    ParentClass MEng.Object;
EndClass;

Imports=
    MEng.System.CQC.Runtime.CQCLogger;
    MEng.System.Runtime.HTTPClient;
    MEng.System.Runtime.URL;
    MEng.System.Runtime.KVPair;
EndImports;

Members=
    // An HTTP client to make server requests
    HTTPClient      m_HTTP;
    String          m_Credentials;
    CQCLogger       m_Log;
EndMembers;


Methods=[Public,Final]

    Constructor()
    Begin
    EndConstructor;



    Method Start([In] String URLStr, [Out] String RetCode) Returns Int4
    Begin
       
        Locals=
            LinesList   OutHdrLines;
            LinesList   InHdrLines;
            URL         URLToGet;
            String      RepText;
            String      ContType;
            MemBuf      DataBuf;
            Card4       ContLen;
            Card4       ResCode;
            KVPair      HdrPair;
            String      BodyText;
        EndLocals;

        Try
            BodyText := "{\"on\": false}";

            ContLen := DataBuf.ImportString(BodyText, Card4.kMaxValue);
            ContType := "application/json";
            InHdrLines.RemoveAll();

            //Set the URL to query
            m_Log.LogMsg1(BodyText, 0);
            URLToGet.Set(URLStr, FQTypes.Full);

            ResCode := m_HTTP.SendPUT
            (
                URLToGet
                , 5000
                , "CQSL/DoHTTPPut"
                , "application/json"
                , RepText
                , OutHdrLines
                , ContType
                , DataBuf
                , ContLen
                , True
                , InHdrLines
            );


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

        Catch
            Return 0;
        EndCatch;

        Return 1;
    EndMethod;
EndMethods;
Reply
#3
If you just do an import string, it will be in ASCII form, so you should probably add an encoding indicator to the MIME format. You could also use a TextXCoder object to transcode it to UTF-8, which is the default for JSON. A lot of the time it won't matter, but you could end up with characters not representable as ASCII.
Dean Roddey
Explorans limites defectum
Reply
#4
(01-21-2020, 02:22 PM)Dean Roddey Wrote: If you just do an import string, it will be in ASCII form, so you should probably add an encoding indicator to the MIME format. You could also use a TextXCoder object to transcode it to UTF-8, which is the default for JSON. A lot of the time it won't matter, but you could end up with characters not representable as ASCII.

I remembered that all of the CQC drivers were there for viewing so I took the SendPUT information straight from your existing Hue driver.

This will be a crude work around until the CQC Philips Hue driver supports groups.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get Field Value via HTTP znelbok 3 964 06-11-2020, 03:43 PM
Last Post: Dean Roddey
  HTTP Trigger and Parameters znelbok 1 697 06-11-2020, 03:41 PM
Last Post: Dean Roddey
  CQC HTTP Events? bjkiller 26 7,605 01-11-2020, 07:27 AM
Last Post: simplextech
  Set value via HTTP Call simplextech 2 991 01-07-2020, 04:39 PM
Last Post: simplextech
  HTTP Trigger Driver - see trained URL's? Shaky 1 1,401 09-15-2019, 12:25 PM
Last Post: Dean Roddey
  HTTP Get driver not working znelbok 10 4,845 08-28-2018, 10:10 AM
Last Post: Dean Roddey
  Http Post zra 17 6,308 08-05-2018, 01:55 PM
Last Post: zra
  HTTP Post zra 7 3,073 05-18-2018, 08:47 AM
Last Post: zra
  IFTT and HTTP Trigger parameter passing setup Shaky 5 4,256 03-09-2018, 10:20 PM
Last Post: Dean Roddey
  SSL certificate for HTTP trigger driver RichardU 7 3,840 01-16-2018, 09:50 AM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)