How to send Data over htpps in Godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Maxim Mäder

I want to send some data to my website/webserver

In the Godot code i use the Template from the docs.

var dict = {'tscn': 'info'}

func _ready():
	_make_post_request('https://keys.quuli.ch/level.php', dict, true)

func _make_post_request(url, data_to_send, use_ssl):
	# Convert data to json string:
	var query = JSON.print(data_to_send)
	print(query)
	# Add 'Content-Type' header:
	var headers = ["Content-Type: application/json"]
	$HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)

func _on_HTTPRequest_request_completed(result, response_code, headers, body):
	var response = body.get_string_from_utf8()
        print(response)

and on my Webserver i just simply print the information that was given like this.

<?php 

print_r($_POST);

Now if i run the script i expect it to return the dict i made at the top but the array returned by PHP is empty … do you have an idea why that is and how to fix it?

:bust_in_silhouette: Reply From: w411-3

If we can expect the template to be functional, and it is evoking a response from your server, I think it’s fair to say it’s probably a php issue. You didn’t really supply enough php to get an idea of what’s going on, so my guess is some configuration or handling of the data on the php side is the issue, not godot.