18 lines
671 B
GDScript
18 lines
671 B
GDScript
extends Node2D
|
|
|
|
@onready var http_request: HTTPRequest = $HTTPRequest
|
|
|
|
func _ready() -> void:
|
|
http_request.request_completed.connect(_request_data)
|
|
http_request.request("http://localhost:9450/api?getVariable=somevariable")
|
|
|
|
func _request_data(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
|
|
print("Result: %d" % result)
|
|
print("Response Code: %d" % response_code)
|
|
print("Headers:", JSON.stringify(headers, "\t"))
|
|
var data := body.get_string_from_utf8()
|
|
var d: Dictionary = JSON.parse_string(data)
|
|
print("Body (str): ", body.get_string_from_utf8())
|
|
print("Body (JSON): ", JSON.stringify(d, "\t"))
|
|
print("Completed")
|
|
|