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

Hi,
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.
CodeCrafter

:bust_in_silhouette: Reply From: Wakatta

You need nothing more than to make an HTTPRequest

Example

func download(link, path):
    var http = HTTPRequest.new()
    add_child(http)
    http.connect("request_completed", self, "_http_request_completed")
    http.set_download_file(path)
    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")
    remove_child($HTTPRequest)

func _ready():
    download("https://godotengine.org/themes/godotengine/assets/logo.svg", "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 itch.io to perform game updates.