HTTP requests always fail in HTML5

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

I’m trying to export my program for HTML5. Whenever I try testing it in a browser, all HTTP requests fail with the response RESULT_CONNECTION_ERROR = 4 --- Request failed due to connection (read/write) error.
HTTP requests work fine when exported for desktop and Android.
I get the same error on Chromium and Firefox.
The error persists whether I’m connecting to my development server or google.

From the documentation:

Note: When performing HTTP requests from a project exported to HTML5, keep in mind the remote server may not allow requests from foreign origins due to CORS. If you host the server in question, you should modify its backend to allow requests from foreign origins by adding the Access-Control-Allow-Origin: * HTTP header.

Maybe this is your issue? I got the text above from Making HTTP RequestsHTTPClient

Juxxec | 2022-11-30 21:47

Thanks, but I don’t think CORS is the issue because I have the same problem when trying to connect to my development server and google.

Unless there is a setting within Godot that may affect it, I don’t see how I can make any impactful changes.

blurrred | 2022-11-30 21:56

You are actually correct. Checking the errors in my browser, it says that CORS is preventing access to my server.
Thank you for your help.

blurrred | 2022-12-01 04:11

How did you manage to fix it? How did you write the request?

Sergey23 | 2023-05-21 10:08

:bust_in_silhouette: Reply From: Juxxec

Converting my comment to a question:

From the documentation:

Note: When performing HTTP requests from a project exported to HTML5, keep in mind the remote server may not allow requests from foreign origins due to CORS. If you host the server in question, you should modify its backend to allow requests from foreign origins by adding the Access-Control-Allow-Origin: * HTTP header.

This is your issue! I got the text above from Making HTTP RequestsHTTPClient