diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/HTTP.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/HTTP.htm index 25fb5953a..84b06bda0 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/HTTP.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asynchronous_Functions/HTTP/HTTP.htm @@ -15,19 +15,70 @@
This section lists the different Asynchronous HTTP functions available in GameMaker. These functions will generate an Asynchronous HTTP Event in all instances that have it:
+This section lists the different Asynchronous HTTP functions available in GameMaker.
+HTTP stands for Hypertext Transfer Protocol, which is a protocol for communication on the World Wide Web. It is used when you browse the internet using a web browser, download files, log in to a website, interact with RESTful APIs, ... It has a variant named HTTPS (S indicating "Secure").
+HTTP requests are sent to a web server, which replies by sending back a response. A request uses one of several methods, of which GET and POST are the most common ones. Both the request and response may contain headers (a collection of key-value pairs) and a request body (the actual data to send). The response contains a status code indicating the status and can contain data (e.g. file contents).
+GameMaker lets you create and send HTTP requests using the functions on this page. The response is returned in an Asynchronous HTTP Event in all instances that have it.
+The most general function is http_request, which allows you to specify any request method as well as headers and data.
+The other functions can be used for more specific requests:
All request functions take a URL. The URL string:
+Note that:
+Let's look at how a general HTTP request is handled from start to end:
+Mouse Left Pressed Event
+var _map_headers = ds_map_create();
+ request_id = http_request("http://www.google.com", "GET", _map_headers, "");
+ ds_map_destroy(_map_headers);
Async - HTTP Event
+if (async_load[? "id"] != request_id) { exit; }
+
+ var _status = async_load[? "status"];
+ if (_status < 0)
+ {
+ // Error occurred
+
+ exit;
+ }
+
+ if (_status == 1)
+ {
+ // Downloading
+
+ exit;
+ }
+
+ if (_status == 0)
+ {
+ // Request completed!
+
+ if (async_load[? "http_status"] == 200)
+ {
+ // Request was succesful
+
+ }
+ }
+
In, for example, a Mouse Left Pressed Event the function http_request is called. The request uses the "GET" method to retrieve a webpage. No headers are passed and the request body is set to an empty string "".
+The Async HTTP event is then triggered one or more times. In this event, the async_load's "id" key is first checked to see if it matches the request_id stored earlier. If not, this event is not for the request made earlier and the code is exited. Next, the "status" key is checked. This can hold one of three values:
While downloading content, the event will trigger multiple times, during which the "status" key will hold the value 1. Finally, it runs a last time and async_load[?"status"] will hold 0 or < 0.
+The last time the event triggers for this request, the "status" key will hold 0. This value indicates the request has completed. The HTTP status is then checked. If it is 200 (indicating "success"), the data can be found in async_load[?"result"].
+The asynchronous HTTP functions send a request to a server, which might take some time to respond. If the server takes too long to respond, the connection may time out. In GameMaker this happens after 60000 ms by default.
The following two functions can be used to get and change this value:
In most cases these functions should not need to be used, but if the game is stored on a secured server - where certain assets may require basic authentication to be accessed and are generating security errors when loading - setting the cross-origin type for image requests to "use-credentials" may be necessary (as opposed to the default "anonymous" setting).
+