I've some trouble for sending a post request to my nodejs server.
I can receive data from the server with GET method, but when I try to send data with POST, I've an empty bracket on return on this function:
func _on_request_completed(result, response_code, headers, body):
var json = JSON.parse(body.get_string_from_utf8())
print(json.result)
print(response_code)
And empty bracket on my JSON console.log on the server too.
My code:
extends CanvasLayer
func _ready():
$HTTPRequest.connect("request_completed", self, "_on_request_completed")
func _on_Button_pressed():
var data = {"name": "Godette"}
_make_post_request("http://localhost:8080/", data, false)
func _on_request_completed(result, response_code, headers, body):
var json = JSON.parse(body.get_string_from_utf8())
print(json.result)
print(response_code)
func _on_HTTPRequest_request_completed():
pass
func _make_post_request(url, data_to_send, use_ssl):
# Convert data to json string:
var query = JSON.print(data_to_send)
# Add 'Content-Type' header:
var headers = ["Content-Type: application/json"]
$HTTPRequest.request(url, headers, false, HTTPClient.METHOD_POST, query)
And this code return this in my console:
{}
200
Thanks for help :)
JSON.parsereturns aJSONParseResultso isjson_result.error == OK? \$\endgroup\$