# Godot and getting files via HTTP

So, I am wanting to use Godot to get a (binary) file using HTTP and then either save it or, even better, turn it into a Resource in memory that I can use. It'll be WAV files that I'm getting in return (trying to implement MaryTTS, which is running as a server on localhost). I had a look at the docs for HTTPRequest, but can't seem to get a working solution.

I do \$HTTPRequest.request("http://...") when a keypress is made, and I have the _on_HTTPRequest_request_completed() function, but this never seems to be called. I tried with the function in the same Node as the request (as per the docs' example), and I also tried putting it as part of a script for the HTTPRequest Node. If I hit the triggering key fast enough, it gives an error ("HTTPRequest is processing a request"), but if I do it slower, it doesn't give that error, so it appears it is finishing. It just doesn't do anything when it finishes. HTTPRequest gives a return value of 0, which I assume means no error? (Or should this give me HTTP status codes?)

Any idea what I'm doing wrong? Can HTTPRequest handle binary files? How do I get this working?

(Any suggestions on a better way to implement MaryTTS are also welcome).

Eventually managed to get this working, using HTTPClient instead of HTTPRequest.

Full code is here: https://pastebin.com/P1GYkvAX

Edit: As requested, some code samples. Basically it's a mix of the threading stuff here (https://docs.godotengine.org/en/3.1/tutorials/threads/using_multiple_threads.html) with HTTPClient from here (https://docs.godotengine.org/en/3.1/tutorials/networking/http_client_class.html)

func _ready():
mutex = Mutex.new()
semaphore = Semaphore.new()

while true:
semaphore.wait()

mutex.lock()
mutex.unlock()

if should_exit:
break

mutex.lock()
_http_get_worker()
mutex.unlock()

func http_get(url_passed = ""):
url_path = url_passed
semaphore.post()

func _exit_tree():
mutex.lock()
mutex.unlock()

semaphore.post()

func _http_get_worker():


Followed by the HTTPClient code, followed by:

        var player = AudioStreamPlayer.new()