Godot Version
4.2.1
Question
Hello everyone,
I’m working on sending an HTTP POST request using Godot’s HTTPRequest node. The request seems to be successful, as I receive a 200 HTTP status code, but the response body is empty. I tested the same request in Postman, and it returned the correct data, so I know the server is responding properly.
# Handle the HTTP request
func make_request(request_type, url, headers, query_params, callback):
if not request_nodes.has(request_type):
request_nodes[request_type] = HTTPRequest.new()
add_child(request_nodes[request_type])
is_processing_finished[request_type] = false
var request = request_nodes[request_type]
if is_processing_finished[request_type]:
request.request_completed.disconnect(callback)
is_processing_finished[request_type] = false
request.request_completed.connect(callback)
var response = JSON.stringify(query_params)
request.request(url, headers, HTTPClient.METHOD_POST, response)
func get_info(userId):
var query_params = {
"userId": userId
}
var request_type = "get_info"
var url = Constant.BasedUrl + Constant.GetInfoUrl
var headers = ["Content-Type: application/json", "User-Agent: Monay"]
make_request(request_type, url, headers, query_params, _on_get_info_request_completed)
func _on_get_info_request_completed(result, response_code, headers, body):
var response = JSON.parse_string(body.get_string_from_utf8())
is_processing_finished["get_info"] = true
emit_signal("GetInfo", response)