I'm developing a game in Godot and I'd like to get some playing statistics. As of now I can save them locally to a json file and I'd like to upload the file to a server after the game is over.
This code taken basically from here allows me to send a dict to the server:
var HTTP = HTTPClient.new()
var url = "http://10.40.11.166/"
var RESPONSE = HTTP.connect("10.40.11.166",80)
while(HTTP.get_status() == HTTPClient.STATUS_CONNECTING or HTTP.get_status() == HTTPClient.STATUS_RESOLVING):
HTTP.poll()
OS.delay_msec(300)
assert(HTTP.get_status() == HTTPClient.STATUS_CONNECTED)
var data = {"a": 2, "b" : 3}
var QUERY = HTTP.query_string_from_dict(data)
var HEADERS = ["User-Agent: Pirulo/1.0 (Godot)", "Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(QUERY.length())]
RESPONSE = HTTP.request(HTTPClient.METHOD_POST, url, HEADERS, QUERY)
assert(RESPONSE == OK)
while (HTTP.get_status() == HTTPClient.STATUS_REQUESTING):
HTTP.poll()
OS.delay_msec(300)
# # Make sure request finished
assert(HTTP.get_status() == HTTPClient.STATUS_BODY or HTTP.get_status() == HTTPClient.STATUS_CONNECTED)
which I can then convert to json with:
json_encode($_REQUEST)
From my PHP server.
Unfortunately, as soon as the dict is more complex (i.e. a dict of dicts or a dict of arrays) the json formatting screws up.
What's the best way to proceed? Is there a simple way to send a named list of arrays or a more complex data structure to a php server?
Alternatively, what is a combination of GDScript with HTTPClient and php file on server side that would allow me to upload a file from "user://" to server? Some "proof of concept" combination of both client side and server side that can upload a file would help me a lot! I've seen this but I couldn't get it to work.
Thanks!