HISE Logo Forum
    • Categories
    • Register
    • Login

    Server.callWithPost content type

    Scheduled Pinned Locked Moved General Questions
    15 Posts 3 Posters 390 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.
    • d.healeyD
      d.healey @hisefilo
      last edited by

      @hisefilo said in Server.callWithPost content type:

      x-www-form-urlencoded

      Why do you think HISE uses this?

      You can (should) send a JSON object with your POST requests.

      Here's an example - https://codeberg.org/LibreWave/Rhapsody/src/branch/main/Scripts/LicenseHandler.js#L99

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      hisefiloH 1 Reply Last reply Reply Quote 0
      • hisefiloH
        hisefilo @d.healey
        last edited by

        @d-healey I tested with a local python server (attached) and got this for headers. Despite this, I think HISE is sending form-urlencoded format, and the APIs I'm testing expect a JSON dictionary for the body.

        Interface: "Host: 127.0.0.1:4000\nContent-Type: application/x-www-form-urlencoded\nUser-Agent: HISE%20Standalone/4.1.0 CFNetwork/1410.0.3 Darwin/22.6.0\nConnection: keep-alive\nAccept: */*\nAccept-Language: en-GB,en-US;q=0.9,en;q=0.8\nContent-Length: 41\nAccept-Encoding: gzip, deflate\nnxi-api-key: sk_f3298fc4aeccb17ab56044222219110d7e044e921ac1cc1a\n\n\r\ntext=hi%20there&duration_seconds=5"
        

        7f43a9fdd0a9d638d8634cca4b5ac824-12602f5c1fdc8a35112ca130a4de9cb890109cc3.zip

        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @hisefilo
          last edited by d.healey

          @hisefilo I've just tested and it is indeed sent as application/x-www-form-urlencoded by default.

          You can specify the content-type you'd like to use by setting a http header before making the POST request.

          Server.setHttpHeader("Content-Type: application/json");

          I'm using this site to test - https://posttestserver.dev/

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          hisefiloH 2 Replies Last reply Reply Quote 0
          • hisefiloH
            hisefilo @d.healey
            last edited by

            @d-healey Yes, header does not seems to be the problem for me. I know hot to add it.
            The JSON itself is sent as form-urlencoded and I guess I need it JSON object
            like this:

            '{\n  "text": "hello",\n  "time": 5\n}'
            

            This is an api call to openai I was playing with. But no luck. credentials are active.

            HiseSnippet 1212.3ocsVs0aaaCElJIpq1ccXEXOtGH7StCI1VwNNWFFVicRZbRiiWbtzhsg.ZI5JFSQpRR4Zuh9ed+C1NTVwWZS1JB1zCB5bke5bkcTRepVKUHm7mONlhb9Z2tiElvlgDl.0ZOjyW4VoTkRdnFiiIZMM.43r7KsBcxsBJ84O+4FDNQ3SmwBgtTx7ouhEwLy314EGy37CHAzyYQyocsWzxWJZJ4xD.HK6VAES7GPdKsMwp1RtnCI5PjyO3VYi5T5lU6GDPpVMnd85au01011izuRMROu5aWa8Zat9Va1G47n8CXFopqgXnZjyJMjAi6FJeuXxAbISy5woVBOTW3jmv9.IOv9KZ4hZFx3ActMBoQfW5LKds7j3024dBKfMk+r312lJ.Oyh4CfNKsH7VdA34MO7pLG7tCH4LGjVYBjdlaWeEK1LShEOOwskvPU8IPdZdnLQWzRatraSIngvTJhLfdfBHlZQw5UprJFd87eLe97copgTUIM0zfnoWb1qJVHzXh06TtLIlURFSEDVIeYT4Bf9yz9PPoCoP5WUrP1YslEx6fIwwblOwvjhx2nkheSrahITpX+QJucvMnDEUg0CVKVIuYsAsNVNLL7kWzJn5gWwF791js18FgT0+rgWb0P5vdT00Qiia24xj3FIaLxOox35iF50dzw8acfrwUua.s5wuKow4Uav6M3fit7TeuHt2uvqc4.pNza2KFsa2gsCUcNZ.ocy9MZ2g25B+ZqSNhzUKSZeT8a1X8WyqEPpb8nluIf0Vc0wCqextERiQ4gJZsAOjnvwX7Og+PdL7THRFP4E1AW3swl0pIKrZFaHOA06ZPxulxw97goekpiRxoVKSzTUlcSk4OIZZE+dEyPwDLTHNHAS5ISLXBqvT8+X5W+d9OlhxxkwcNs64XeBmealx98ULSnUPwBkG5U1OjXJC4yXN0lNzEVEGuJtehv2RVTCUwI5UwJpNFjReN.874fLrFfboXESXJZT1xnoZ.wnbkKunJ2JrDUojpRwDEIBz6iowyaOLrTzVZnmJJ977eHet7vuymJpe+6TlshChgbn56tDaGIo9mLrnHIBJqVExo7D5TEg1tE6kcu+d44G0jkxlSQonkfYNE5dtuAPnrtFaeeFp.UMoc8eSVWeiDiQJPLn4NmaOinKUDfRg77SrQWzZOhgbqi.eBmSLUYX1eAm8nCgw2SFmjycOpdfQFCGUSnFPJrHvw8K3XGM+FgwySXni.e7X28ECYDk8G6Sc7Syb7qH8n7T+9DWyHKLifwU2mma8hId9QtgRN4KyuO0k2ieVVw28542j44u2cea4IlJvbBFJeY9LSRvN3ZUpAq39rowvd.YPBmXVb4fcEZl.nJagIx1otBMyLd9D1+YaL9Rg3yb6vL9g2MFW5NvHTK8+AFy1y9T2862m5alAvUbO30++rTEcFLzjId6IDihA0CtsSh5B2MwmBmtPP41tbmkr8iSnqXosQ.aUeJweAOYB8rzNYB8tUHJh3qjW6OoK1tI+wob.LIRu0SN2SrzXuOs4EghfKVbsu+ht5yLb8GpgUenFV6gZ3FOTCq+PMbyGpga8uan8dev0WjQSZaPnS5re5vVGm8EDnBLsZE82v9LJiT
            
            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @hisefilo
              last edited by d.healey

              @hisefilo You need to set these are separate headers I think.

              Server.setHttpHeader("Content-Type: application/json\nAuthorization: Bearer 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");
              

              I'm seeing this in the console with your snippet

              Interface: {
              "error": {
              "message": "Invalid URL (POST /v1/chat/completions/)",
              "type": "invalid_request_error",
              "param": null,
              "code": null
              }
              }

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              1 Reply Last reply Reply Quote 0
              • hisefiloH
                hisefilo @d.healey
                last edited by

                @d-healey here's clear. posted on posttestserver.dev via HISE, and via mac terminal cURL

                HISE json (see body)

                Screenshot 2024-11-27 at 13.30.18.png

                cURL Json

                Screenshot 2024-11-27 at 13.36.17.png

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @hisefilo
                  last edited by

                  @hisefilo said in Server.callWithPost content type:

                  here's clear. posted on posttestserver.dev via HISE

                  Share snippet

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  hisefiloH 1 Reply Last reply Reply Quote 0
                  • hisefiloH
                    hisefilo @d.healey
                    last edited by

                    @d-healey

                    HiseSnippet 1213.3ocsVs0TabCEVKvlI3zzoYl9XePiexoCDaiWLW5zoAaffgfwEykjosCi7txrBKKsHo0wtYx+49On8ncWrWHPaFll8AOVma5Smy24H0QI8oZsTgbJbxjHJx4ab6NQXBaFRXBTqsQNemaGo1bBUa5RUinJTiIQDslFfbbl+MVqbVbATx2e8KMHbhvmNSDBclj4SeKaHyLSZmWe.iy2kDPOgMLm0dutkuTzTxkw.hl2sBJh3OfbIsMwZ1btn8H5PjyO5VY05T5Z05GDPpUKnd85ar9FdaTkzuhGoW05a3sh2Zqr9Z8QNOYm.lQp5ZHFpF4rPCYvjtgxOHR2fyXZVON0tnJpKryoh2UxCrGQqTTyPFOnyMoJMBhRmYIt4SSbeu6gr.1T44SfVE3YdjOA5L2sg272BdUyCuJ4f28.ImbPZgTH8B2t9JVjYlFKddlaKggp5Sf5TdnjZKZtpy61TBVHLuZHY.cWErXpGkpWoxRX3mW9SEJTHkQ7JM0zfnomd7aKULzXhzaVtbDPZfSjQmZR.cTQvkYNrGX2dTfAnJULa6V1h5MwjnHNymXXRQ4qzRwuK1J1DJUr+LQ1l3FThhpv5AKGojWs7fVGHGEF9lSaETauyYC9Pax5ackPp5e7nSOeDcTOp5hgShZ2QSzmEG0Hd0w9wUlTe7npsGeP+V6Jab90Cn0N353FmTqAu2fc2+ri7qNjW8W4dmMfpCqt0oi2p6n1gpN6OfztY+Fs6vacpu2Jj8Ic0x316W+pUW4cbu.RkKF278Ar1pyOXT8C2pXRlp.vq0F7HhBGgw+L9iEvvWwgx.Ju3l3hWFYV1SVboLwP0BX8ZPyukHw98wo+KwFkjSsdFCY3L+lpyOMgZU+AEyPwDLPGGDiI8jwFLgUbp8eJ4e+QgOkfxxkwcNp6IXeBmeSwx9+yYlPqhREKGUdEJ4503J90qNZcuJWdURst3R3nkv8iE91hTIMvmi0KgUTcDbxouDfegEgBsFf8qhTLgojQYITSs.xS2wfzf.x+TRN7lfikh1RC8HQoWV3iEVr.bDtqp98uWcVhFj23.o69TaGFo92brjHdHvlVBpi7X5TCgFta2E69vcw4GxjUlxYnTzRvLGEQEOznGTVyhsiOCUfolj98uMqeuQrwHEHFzVunaOinKUDfRfb9Y0nSasMwPtIPPLg8IhpLL6QvYa5HXvc5fjEc2lpGXjQvV0TNDpWVD339ErsiyeWvj7KLzwPLdp6NhQLhxdvtafedVfeKoGkmD2m4ZFag4PXP0CE4VuNMxOwMTxIeYw84t7d7iyXhOXjeeVj+A2cTJoBSEXNACDVlOyDGrI1qhGb41mMGFtAPFDyIlaesf8xyLE.K6VyhsyaEZlYR9B1+a2U7kBwW31gY7CueLN28fQfK80.iY2v9b2c52m5alAvEb28cectNEcLLnjIt7PhQw.9fa63gcgWk3SgcWHnbaWtyb19wz0UrqsY.KqOYweCeYJqZW6jor5MJQCI9J4E9ocw16veZhD.Shj26rn6g103p2s4EgFBOo3Be+aGpOywUdrNV6w5n2i0wUerNV+w53ZOVGW++1Q6K9fWsHGl11fPG1YmjgsNN6HH.CLgsh9G.3GcMqA
                    
                    d.healeyD 1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey @hisefilo
                      last edited by

                      @hisefilo Yeah looks like HISE (or JUCE) is repackaging the data. One for Christoph I think.

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      hisefiloH 1 Reply Last reply Reply Quote 1
                      • hisefiloH
                        hisefilo @d.healey
                        last edited by

                        @d-healey thanks mate for taking the time! hope @Christoph-Hart can take a look!

                        oskarshO 1 Reply Last reply Reply Quote 0
                        • oskarshO
                          oskarsh @hisefilo
                          last edited by

                          @hisefilo can confirm this bug.

                          Basically this will block HISE to work with any API where it needs to send data as JSON.

                          If you implement a custom server you can handle this but when using something like supabase it will not work.
                          I remember I had the same code working when I wrapped it in a string and made sure it was correctly formatted.

                          So this code was working, but unfortunately a type checked has been added to the callWithPOST parameter which checks for a valid JSON type.

                          inline function getLogin(email, password)
                          {
                              local parameter = '{
                                  "email": "'+email+'",
                          	"password": "'+password+'"
                              }';
                          		
                          	Server.callWithPOST(LOGIN_URL, parameter, onLoginCallback);
                          }
                          

                          @Christoph-Hart can you look into this please since its making networking in HISE not really possible

                          HISE Developer for hire :)

                          d.healeyD 2 Replies Last reply Reply Quote 0
                          • d.healeyD
                            d.healey @oskarsh
                            last edited by

                            @oskarsh said in Server.callWithPost content type:

                            its making networking in HISE not really possible

                            You can use cURL

                            Libre Wave - Freedom respecting instruments and effects
                            My Patreon - HISE tutorials
                            YouTube Channel - Public HISE tutorials

                            1 Reply Last reply Reply Quote 0
                            • d.healeyD
                              d.healey @oskarsh
                              last edited by

                              @oskarsh Give this a try and let us know if it works

                              https://forum.juce.com/t/solved-using-juce-url-to-send-post-with-body/59701/2

                              Libre Wave - Freedom respecting instruments and effects
                              My Patreon - HISE tutorials
                              YouTube Channel - Public HISE tutorials

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

                              50

                              Online

                              1.7k

                              Users

                              11.7k

                              Topics

                              102.2k

                              Posts