Godot Version
4.4.1
Question
I have the following code, which works when I test the independent scene that it’s in. But once I add this into my main scene and then run the main scene, the _on_request_completed
actually never fires. I can’t figure out why…
extends HTTPRequest
@export var base_url: String = "https://someUrl.com/v1"
@export var api_key: String = "someKey"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Connect the request_completed signal
get_mission_by_lesson_title("Patterns in Two-Way Tables")
func get_mission_by_lesson_title(lesson_title: String):
# Properly construct the URL with the endpoint and proper URL encoding
var url = base_url + "/isometric-game?title=" + lesson_title.uri_encode()
print("Fetching missions with URL:::::", url)
# Headers should be passed directly to the request method
var headers = ["x-api-key: someKey"] # Note: space after colon removed
request(url, headers)
func _on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
print("FETCHING MISSION::::::")
var json = JSON.parse_string(body.get_string_from_utf8())
print("MISSION DATA:::", json)