Making HTTP requests

    For the sake of this example, we will create a simple UI with a button, that when pressed will start the HTTP request to the specified URL.

    Create a new empty scene, add a CanvasLayer as the root node and add a script to it. Then add two child nodes to it: a Button and an HTTPRequest node. You will need to connect the following signals to the CanvasLayer script:

    • HTTPRequest.request_completed: When the request is completed, we will get the requested data as an argument.

    With this, you should see printed on the console; hello being a key, and world being a value, both of them strings.

    For more information on parsing JSON, see the class references for and JSONParseResult.

    Note that you may want to check whether the equals and whether a JSON parsing error occurred, see the JSON class reference and for more.

    Please note that, for SSL/TLS encryption and thus HTTPS URLs to work, you may need to take some steps as described here.

    Also, when calling APIs using authorization, be aware that someone might analyse and decompile your released application and thus may gain access to any embedded authorization information like tokens, usernames or passwords. That means it is usually not a good idea to embed things such as database access credentials inside your game. Avoid providing information useful to an attacker whenever possible.

    Until now, we have limited ourselves to requesting data from a server. But what if you need to send data to the server? Here is a common way of doing it: