HISE Logo Forum
    • Categories
    • Register
    • Login

    Server.callWithPost content type

    Scheduled Pinned Locked Moved General Questions
    16 Posts 4 Posters 523 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 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+49On8ncWrWHPaFll8AOVma5Smy24H0QI8oZsT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IhpLL6QvYa5HXvc5fjEc2lpGXjQvV0TNDpWVD339ErsiyeWvj7KLzwPLdp6NhQLhxdvtafedVfeKoGkmD2m4ZFag4PXP0CE4VuNMxOwMTxIeYw84t7d7iyXhOXjeeVj+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

                  d.healeyD HISEnbergH 3 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
                      • HISEnbergH
                        HISEnberg @oskarsh
                        last edited by

                        @oskarsh @hisefilo

                        I figured out a way to solve this (sort of, a better method would be a new scripting call for the Server API, something like Server.callWithPostRawJSON).

                        Most of where you want to look is the GlobalServer.cpp file here

                        If you are looking for a quick fix you can try editing line 273 of the GlobalServer.cpp script:

                        for(const auto& v: d->getProperties())
                        			isComplexObject |= v.value.isArray() || v.value.getDynamicObject() != nullptr;
                        
                        		// if(isComplexObject) remove this line
                                if (true) // add this line
                        		{
                        			extraHeader = "Content-Type: application/json";
                        			url = url.withPOSTData(JSON::toString(parameters, true));
                        		}
                        		else
                        		{
                        			for (auto& p : d->getProperties())
                        				url = url.withParameter(p.name.toString(), p.value.toString());
                        

                        I think what happens is that when your JSON objects contain only simple properties (strings, numbers, booleans), HISE will treat it as a simple object and URL-encodes the parameters. So modifying the isComplexObject will just push the JSON data for all objects now (which could cause more issues down the line).

                        I'll post here again once I figure out a better/more robust solution.

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

                        14

                        Online

                        1.8k

                        Users

                        12.1k

                        Topics

                        105.7k

                        Posts