|
| 1 | +---[SHARED AND MENU] Launches an asynchronous **GET** request to a HTTP server. |
| 2 | +--- |
| 3 | +--- HTTP requests returning a status code >= `400` are still considered a success and will call the Structures/HTTPRequest callback. |
| 4 | +--- |
| 5 | +--- The Structures/HTTPRequest callback is usually only called on DNS or TCP errors (e.g. the website is unavailable or the domain does not exist). |
| 6 | +--- |
| 7 | +--- A rough overview of possible Structures/HTTPRequest messages: |
| 8 | +--- * `invalid url` - Invalid/empty url ( no request was attempted ) |
| 9 | +--- * `invalid request` - Steam HTTP lib failed to create a HTTP request |
| 10 | +--- * `error` - OnComplete callback's second argument, `bError`, is `true` |
| 11 | +--- * `unsuccessful` - OnComplete's first argument, `pResult->m_bRequestSuccessful`, returned `false` |
| 12 | +--- |
| 13 | +--- This cannot send or receive multiple headers with the same name. |
| 14 | +--- HTTP-requests that respond with a large body may return an `unsuccessful` error. Try using the [Range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range) header to download the file in chunks. |
| 15 | +--- |
| 16 | +--- HTTP-requests to destinations on private networks (such as `192.168.0.1`, or `127.0.0.1`) won't work. |
| 17 | +--- |
| 18 | +--- To enable HTTP-requests to destinations on private networks use Command Line Parameters `-allowlocalhttp`. (Dedicated servers only) |
| 19 | +--- |
| 20 | +---[(View on wiki)](https://wiki.facepunch.com/gmod/http.Fetch) |
| 21 | +---@param url string The URL of the website to fetch. |
| 22 | +---@param onSuccess? fun(body: string, size: integer, headers: table<string, string>, code: integer) Function to be called on success. Arguments are |
| 23 | +--- * string body |
| 24 | +--- * number size - equal to string.len(body). |
| 25 | +--- * table headers |
| 26 | +--- * number code - The HTTP success code. |
| 27 | +---@param onFailure? fun(error: string) Function to be called on failure. Arguments are |
| 28 | +--- * string error - The error message. |
| 29 | +---@param headers? table KeyValue table for headers. |
| 30 | +function http.Fetch(url, onSuccess, onFailure, headers) end |
0 commit comments