HISE Logo Forum
    • Categories
    • Register
    • Login

    Help with getCallWith

    Scheduled Pinned Locked Moved General Questions
    19 Posts 5 Posters 789 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 @DanH
      last edited by

      @DanH The response from your server is in the response variable ;)

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

      DanHD LindonL 2 Replies Last reply Reply Quote 0
      • DanHD
        DanH @d.healey
        last edited by

        @d-healey aahh ok, great, make sense, thanks both!

        DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
        https://dhplugins.com/ | https://dcbreaks.com/
        London, UK

        1 Reply Last reply Reply Quote 0
        • LindonL
          Lindon @d.healey
          last edited by

          @d-healey said in Help with getCallWith:

          @DanH The response from your server is in the response variable ;)

          @DanH so you are likely getting a string back in response, so...

          reg myJSON = response.parseAsJSON();
          Console.print(myJSON.VERSIONnumber);
          

          HISE Development for hire.
          www.channelrobot.com

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

            @Lindon if the string is a JSON it will parse it automatically for you.

            LindonL 1 Reply Last reply Reply Quote 1
            • LindonL
              Lindon @Christoph Hart
              last edited by

              @Christoph-Hart said in Help with getCallWith:

              @Lindon if the string is a JSON it will parse it automatically for you.

              so you are saying this works?

              response.VERSIONnumber
              

              ??

              HISE Development for hire.
              www.channelrobot.com

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

                @Lindon yes

                LindonL 1 Reply Last reply Reply Quote 0
                • LindonL
                  Lindon @Christoph Hart
                  last edited by

                  @Christoph-Hart cool.

                  HISE Development for hire.
                  www.channelrobot.com

                  1 Reply Last reply Reply Quote 0
                  • Dan KorneffD
                    Dan Korneff
                    last edited by Dan Korneff

                    Can you guys give me a hand with a simple POST request? I probably need a tee-shirt, but I can't see what I'm doing wrong.
                    In short: I'm sending my name to a php script, and I'm expecting to get a response containing a status and message formatted in json.
                    My php code looks like this:
                    https://www.mytestserver.xyz/testing/simple-response.php

                    <?php
                      // check if form has been submitted
                      if (isset($_POST["name"])) {
                        $name = $_POST["name"];
                        // create response array
                        $response = array(
                          "status" => "success",
                          "message" => "Hello, " . $name . "!"
                        );
                        // return response as JSON
                        header("Content-Type: application/json");
                        echo json_encode($response);
                      } else {
                        // return error if form has not been submitted
                        $response = array(
                          "status" => "error",
                          "message" => "No name provided."
                        );
                        header("Content-Type: application/json");
                        echo json_encode($response);
                      }
                    ?>
                    
                    

                    If I navigate to the page, I get an expected response:

                    {
                    "status":"error",
                    "message":"No name provided."
                    }
                    

                    If I use postman.co and enter in some key data, I get an expected response:

                    Screenshot from 2023-01-26 17-19-49.png

                    My HISE script looks like this:

                    HiseSnippet 928.3ocsVs0aaaCElxIbnR6BVA5dWvOo.3lXu01MzhgkYGmMikKFQoc6sBFJ5HhPQpQRkUsg7WZ+11+fsCkjsjyb6JLV8CB3b+67QdNzy0JJyXTZjm+kk4Lj2mfiKk1zIoDtDM6Hj2Wf+wYwSCOgSYRCKLtzXYYnwk4Digkf7714Gbt54uKp52e8ciIBhjxZUgPuRAgeBOiaa0N+vehKDGSRXWxy538SNbFUImnDpB.V6fGhxIzaHWyNi3bqGF48QSS3VkN1RrLCxa2wpjx3T0uIq8+UbC+JAyILBECIpV8wJQhCwNsnIobQx7ksuAAYYdKYrSMY7H7o7D9J8sjxmWYHrMht7gWu0g2NqAuQcg2vNvaCPxqCj1sFRODGS07baqEGd9X7LokoWP.ZuKTp8E06O6gmn.Oj18yH2vNVCBqhH5YCGNHD9r2KBBhY5aY58ML6Xhg8xKNIpep0lad9AGjUBsi0T6vaJ+8C5CA.GUFa3sDc33BqUIGE9sgKK00L6DUVtRBBQ8ar6BJHfKEbIKbQgjZ4JYngmkKXWv90BnDQ6E7GA9BEkHByIZ3XGPJj2.ePseeInn+yC6aSAhzjUVIG3e2KB7C7avODp3m41z4mGeYTeGt4xqOntJOVyL.nLr8ySy6OnsDCVgmHCb1UXFDtz08pqMzYFk.BTygVxpcr2JWfFy+N3ycapAUxl92QNZkHhtjYF.rmnfU0y7EQMBUk6drhK+AUo++fgcGeM0YBPDWAyOQ2G.P15.tyTV14xZhO3tfv6aZwhMZqIWBldilcC152UfQxhrqbDeKE3bDtsu9HD9sOB0cBmVSKcbTImI41yyYx21bOpgKciaMnBb0VMr8YMCa0LGhCyT93FZDUA4tK4Pub1QDKYYhfbB0ImosbWK3cD6VXIX8TrO9Hl4FqJux2lCPnMeOJ6aVUxv7CKaq+hC4lSUYPdH5xll8eu9.VboRJDD65aybqvaL.mOqsBwslPZ31xtq3+eaE26KDeHdN2RS2LF6sALBmBeHvXyCCeJd5hELpsEf6hO9W9v7J.5BUga60oDqlCm93yJxhg2FoLn5RIS3lO754tIWKOzI6XfXlLoR3ugeMFG4j8ZLNZoQTFgpUulVe+28zyCpz.XRV8pqO9Tmb3pq8X7v8GhxfWAeMk5Z+GC221bLe4VDyWsEw7jsHlmtEw7rsHludKh4admw39CHeegUkUON.JlOsZ8im2TIAtYUcKD8O0FDwOB
                    
                    Server.setBaseURL("https://mytestserver.xyz/");
                    const var Button1 = Content.getComponent("Button1");
                    
                    
                    inline function simpleRequest()
                    {
                    	local parameter = 
                    	{
                    		"name": "thisismyname"
                    	};
                    	
                    	Server.callWithPOST("testing/simple-response.php", parameter, function(status, response)
                    	{
                    		Console.print(trace(response));
                    	});
                    };
                    
                    
                    inline function onButton1Control(component, value)
                    {
                    	if(value)
                    	{
                    		simpleRequest();
                    	}
                    
                    };
                    
                    Content.getComponent("Button1").setControlCallback(onButton1Control);
                    

                    The response is timing out

                    Screenshot from 2023-01-26 17-16-00.png

                    I'm sure it's something simple that I'm overlooking. Anyone see an issue?

                    Dan Korneff - Producer / Mixer / Audio Nerd

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

                      I think you need to use the return keyword to get the value, and just return the array, don't use json_encode.

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

                      Dan KorneffD 1 Reply Last reply Reply Quote 0
                      • Dan KorneffD
                        Dan Korneff @d.healey
                        last edited by Dan Korneff

                        @d-healey instead of echo?

                        Trying that, I get this error when I navigate to the page in a web browser:

                        SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
                        

                        And there is no change when I try in hise

                        EDIT: just re-read your reply. Trying that now.
                        ok tried

                        <?php
                          // check if form has been submitted
                          if (isset($_POST["name"])) {
                            $name = $_POST["name"];
                            // create response array
                            $response = array(
                              "status" => "success",
                              "message" => "Hello, " . $name . "!"
                            );
                            // return response as JSON
                            header("Content-Type: application/json");
                            return $response;
                          } else {
                            // return error if form has not been submitted
                            $response = array(
                              "status" => "error",
                              "message" => "No name provided."
                            );
                            header("Content-Type: application/json");
                            return $response;
                          }
                        ?>
                        
                        

                        Getting the same syntax error. I believe "return" only works within a function

                        Dan Korneff - Producer / Mixer / Audio Nerd

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

                          @Dan-Korneff

                          Getting the same syntax error. I believe "return" only works within a function

                          Ah yeah that's right. I didn't notice it was outside a function. Try putting it in a function, see if it makes a difference...

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

                          Dan KorneffD 1 Reply Last reply Reply Quote 0
                          • Dan KorneffD
                            Dan Korneff @d.healey
                            last edited by

                            @d-healey does this look right?

                            <?php
                            function simpleResponse()
                            {
                                // check if form has been submitted
                              if (isset($_POST["name"])) {
                                $name = $_POST["name"];
                                // create response array
                                $response = array(
                                  "status" => "success",
                                  "message" => "Hello, " . $name . "!"
                                );
                                // return response as JSON
                                header("Content-Type: application/json");
                                return $response;
                              } else {
                                // return error if form has not been submitted
                                $response = array(
                                  "status" => "error",
                                  "message" => "No name provided."
                                );
                                header("Content-Type: application/json");
                                return $response;
                              }
                            }
                            
                            echo $response;
                            ?>
                            

                            Not working here

                            Dan Korneff - Producer / Mixer / Audio Nerd

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

                              @Dan-Korneff Where are you calling the function?

                              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
                                last edited by

                                Actually forget about that. I just tested on my localhost and your original code works here.

                                I modified it slightly but I don't think it makes a difference.

                                <?php
                                  // check if form has been submitted
                                    $response = [];
                                
                                  if (isset($_POST["name"])) {
                                    $name = $_POST["name"];
                                    // create response array
                                    $response = array(
                                      "status" => "success",
                                      "message" => "Hello, " . $name . "!"
                                    );
                                    // return response as JSON
                                    header("Content-Type: application/json");
                                  } else {
                                    // return error if form has not been submitted
                                    $response = array(
                                      "status" => "error",
                                      "message" => "No name provided."
                                    );
                                    header("Content-Type: application/json");
                                  }
                                  echo json_encode($response)
                                ?>
                                

                                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
                                  last edited by

                                  Oh I see your mistake (I think) you are missing www. in your url.

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

                                  Dan KorneffD 1 Reply Last reply Reply Quote 0
                                  • Dan KorneffD
                                    Dan Korneff @d.healey
                                    last edited by

                                    @d-healey My hero!!! that was it

                                    Dan Korneff - Producer / Mixer / Audio Nerd

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

                                    50

                                    Online

                                    1.7k

                                    Users

                                    11.7k

                                    Topics

                                    102.0k

                                    Posts