How to download files from the internet using gdscript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CodeCrafter

I would like to know how it is possible to download files from the internet using GdScript. I would like to use this to add a function to my game that allows you to download updates via the game. I have already found posts about it, but they were a bit older and therefore a class used there no longer worked. Can someone help me there? Thanks in advance.

:bust_in_silhouette: Reply From: Wakatta

You need nothing more than to make an HTTPRequest


func download(link, path):
    var http =
    http.connect("request_completed", self, "_http_request_completed")
    var request = http.request(link)
    if request != OK:
        push_error("Http request error")

func _http_request_completed(result, _response_code, _headers, _body):
    if result != OK:
        push_error("Download Failed")

func _ready():
    download("", "Logo.svg")
:bust_in_silhouette: Reply From: Calinou

See Making HTTP requests in the documentation.

Note that developing a in-game update system has security considerations – you want to make sure files served to players haven’t been tampered with. This is difficult to do right, even for professional game developers. Instead, it’s better to rely on launchers such as Steam or to perform game updates.