Forum
    • Categories
    • Register
    • Login

    callWithPOST change content type

    Scheduled Pinned Locked Moved General Questions
    24 Posts 3 Posters 1.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Christoph HartC
      Christoph Hart @David Healey
      last edited by

      @d-healey yes but this is solved - you have to pass in the JSON as string to append it as POST data - I‘ve removed the type check that only accepted JSON objects for this method.

      David HealeyD 1 Reply Last reply Reply Quote 1
      • David HealeyD
        David Healey @Christoph Hart
        last edited by David Healey

        @Christoph-Hart Ah yeah, just tested and it's working here

        https://posttestserver.dev/p/y1n6045ukg04hp7k/latest

        HiseSnippet 1210.3ocsVs0TaaDEdEfxDbZ5zLSerOriexzAhk.gSBc5zfMPvPv3h4Rxz1gYszZzhj1UY2UF6lI+m6+f1yJIrMDnMCSidvi2ys8aOmuyY2tRgOUoDRjUkiGmRQVeicuwbcXqPBiiZuEx56r6JT5ioJcOpbHUhZNNknTz.jk07uwXk0hKfx+9qeoIIlv8oSEgPmJX9z2xRX5oR6958Yww6PBnGyRlwZuW21WvaIhEY.hl21AkR7iHWP6PLlMmMZWhJDY8i19MVcs9NMB7ItubcO+0CHAj0dEwKviNvyaUGGW5.mWQGfrdz1ALsP1SSzTExZglhfw8BEWwK1fSYJV+XpYgKpGryEh2QDGXNhFonVgr3ftWmpTHHJcml3luHw881GvBXSjOaBzn.O0iYSfVycS3M+Mfm6rvyYF3cGPxZFHsPAjdlcOeIKUOUiAOOwtMWSkCHPcZVnTXKZN24saI.K35mmPhn6HgES7nVCGmkwvOK8SUpTofQ7bEU2jnnmbzaqUMTqSUaTudJPZfSjVUXR.cXUvkoNrKX2tTfAHqUsb6Vwf5MvjzzXlOQyD75WpD7emuYlNTHY+YtrMvMoDIUhUQqjJEWtRT68ECCCeyIsCVa2yXQW0g7xMujKjCNZ3ImMjNrOUddx3zNcUD0oYoMyVejely3FiF51Yz9CZuin4YeHht19eHq4wq0LtezN6c5g9tIwt+Zr2oQTUn6lmLZydC6DJ6tWDoSqAM6zMt8I9dqR1izSIx5rWiKWe02E6EPbNeTq2Gv5HOa+gMNXyp4YpJ.uVowCIRbJF+y3OVACeUSDAz3pafqdQpdEOQ0kKECUKf0q.M+VtDy2Gm7ubajhXpwyLHCW52Dc9EITi5qjLMESv.cLJCS5KxzXBq5D6+T9+9iJeJGk0qi6dXuiw9j33qKVl+eFSGZTTqZ8z5ic4Mb7VOK5BGuvzWDkWqqtLNcY7fLtuoHUSA74L0xXIUkBmb5R.7qrHTnU.redpjw00zRCgZhEPd5VFTDDP9mxygWGbrf2QnoGxqsTkOVYwJvQ31pFL3N0YHZPdKFHc2kZyvH4+li03YI.aZYnNFmQmXHzvcytX66uKd1gLkkoYLTvayY5CSo76azCprYwzwWhJvTcd+92V1u2LSqEbDCZqWztul2ixCP4Pd1Y0nSZuEQStNPPLg8IkJ0LyQvZK5PXvcwfjEs2hphzhTXqZIRf5kAAV1eAa6nYuKX7rKzzQPLdr817gLhzbvtcfeZYfeKoOMNOtOwVOx.yDXP08E41utHxOxNTDS9xh6Ssi6GeTIS7di76Ki7OXusTJjXJGGSv.gk4yzYAaf8b7fK29r4vvM.hfrXh9lWKXt7rTAvxtwrXy7VthoGOaA6+s6J9Rg3yr6xz9g2MFm6NvHvk9ZfwxaXep81CFP80SA3B167tuNWmhNBFTx3Wb.QKY.evtSVRO3UI9TX24bZroK2ZNS+XwZGyZSFvv5yW72vWoRWyZqRktWqDkP7khy8K5hM2g+3bI.l34u2YQ6CLqwt2t4EgRfmTbtu+MC0m43pOTGW6g5n2C0w0enN13g53KdnN9x+aGMu3Cd0hHonsAgNn614Casr1lS.FXNaE8OfASM7C
        

        Edit: Actually this snippet sends it as an object, not a string, and it seems to still work.

        Free HISE Bootcamp Full Course for beginners.
        YouTube Channel - Public HISE tutorials
        My Patreon - HISE tutorials

        Christoph HartC 1 Reply Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @David Healey
          last edited by

          @d-healey if you don‘t convert it to a string then the JSON is converted to post arguments, no?

          David HealeyD 1 Reply Last reply Reply Quote 0
          • David HealeyD
            David Healey @Christoph Hart
            last edited by David Healey

            @Christoph-Hart In the link I posted above, it shows the result like this, regardless of if I convert to a string first:

            content-type application/json

            Body

            { "model": "gpt-4o", "messages": [ { "role": "user", "content": "write a haiku about ai" } ] }

            Edit: Ah but if I don't convert to string it seems to lose the authentication header, strange..

            Free HISE Bootcamp Full Course for beginners.
            YouTube Channel - Public HISE tutorials
            My Patreon - HISE tutorials

            Christoph HartC 1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart @David Healey
              last edited by

              @d-healey ah yes true this is because the JSON has an Array element - HISE checks this and then converts it to a String internally (because it cannot pass an array as post parameter).

              D 1 Reply Last reply Reply Quote 1
              • D
                Daanyoo @Christoph Hart
                last edited by

                @Christoph-Hart I found the mistake - I had accidently reset the Server.HttpHeader() of the request when passing it into the makeHttpRequest function. Therefore only the the Auth Bearer Token was passed and the Content-Type was automatically set by HISE. Now I correctly appended the Bearer Token within the request and everything works perfectly fine :)

                Thank you guys so much for your help, I really appreciate it!!

                Christoph HartC 1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart @Daanyoo
                  last edited by

                  @Daanyoo Alright, good to see it resolved.

                  Ah but if I don't convert to string it seems to lose the authentication header, strange..

                  I just looked at the code and it makes sense:

                  if(isComplexObject)
                  {
                  	extraHeader = "Content-Type: application/json";
                  	url = url.withPOSTData(JSON::toString(parameters, true));
                  }
                  

                  this is the branch if you pass in a JSON with an Array and as you can see it replaces the extraHeader content with the JSON type definition. However this trashes whatever you've set before so your Authentication token goes out the window.

                  There are multiple ways to solve this, but I'm not sure which route to take:

                  1. append (or prepend) the Content Type definition to the existing header (unless there is already a Content type set, then ignore it)
                  2. just don't fiddle with the content type at all here and let the user figure that out.

                  Both are potentially breaking changes (while the first one is less intrusive) so let's proceed with caution here.

                  David HealeyD 1 Reply Last reply Reply Quote 0
                  • David HealeyD
                    David Healey @Christoph Hart
                    last edited by

                    @Christoph-Hart I think the first one is the safest option

                    Free HISE Bootcamp Full Course for beginners.
                    YouTube Channel - Public HISE tutorials
                    My Patreon - HISE tutorials

                    D 1 Reply Last reply Reply Quote 0
                    • D
                      Daanyoo @David Healey
                      last edited by

                      @David-Healey @Christoph-Hart As I've just started building out the Installer of the plugin on a Windows VM I'm strangely running into a error again....

                      As discussed the Server.callWithPOST function worked perfectly fine passing the JSON via trace() as stringified data - however, when trying to execute the same function on Windows the parsed string into the request is rejected due to the type check:

                       local jsonData = trace(data);
                                  
                                  Server.callWithPOST(endpoint, jsonData, function(status, response)
                      

                      Error: Illegal type: string, expected: JSON

                      Is there any other type check embedded here which will only trigger while on Windows?
                      Not sure how I could create a workaround for that..

                      David HealeyD 1 Reply Last reply Reply Quote 0
                      • David HealeyD
                        David Healey @Daanyoo
                        last edited by

                        @Daanyoo Are you using the same version of HISE on both systems? I'm not aware of any Windows specific limitation.

                        Free HISE Bootcamp Full Course for beginners.
                        YouTube Channel - Public HISE tutorials
                        My Patreon - HISE tutorials

                        D 1 Reply Last reply Reply Quote 0
                        • D
                          Daanyoo @David Healey
                          last edited by

                          @David-Healey Yes, both are running on the latest version of HISE - I also didn't expect any OS specific differences here..

                          D 1 Reply Last reply Reply Quote 0
                          • D
                            Daanyoo @Daanyoo
                            last edited by

                            No Matter how I try passing the JSON object into the callwithPOST function, it always arrives in this URL-encoded format, which makes my request for the license activation fail.

                            One for Christoph I guess...

                            Christoph HartC 1 Reply Last reply Reply Quote 0
                            • Christoph HartC
                              Christoph Hart @Daanyoo
                              last edited by

                              @Daanyoo have you tried trace(ob) before passing it in? There is some funkiness going on with Post parameter handling. You might also have to call a header that sets the json content type.

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post

                              25

                              Online

                              2.2k

                              Users

                              13.4k

                              Topics

                              116.3k

                              Posts