0 votes

Will there be a method (or is) to download a string via https from a server with only a few lines of code like in C# with WebClient.DownloadString and not with 30 lines or so like here
Godot HTTP client class?

in Engine by (49 points)

1 Answer

+1 vote
Best answer

Yes, I had the same problem, then I found this.
Add an HTTPRequest node in the editor called http. Then you can simply:

$"http".request(url)

To get the result of the request you can use connect to register a method that will be called when the request is completed:

$"http".connect("request_completed", self, "_on_request_completed")

The method will look like this:

func _on_request_completed(result, response_code, headers, body):
    $"http".disconnect("request_completed", self, "_on_request_completed")
    if result == HTTPRequest.RESULT_SUCCESS and response_code == 200:
        var parsed_json = str2var(body.get_string_from_utf8())
    else:
        printerr("Request error")
by (46 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.