Garry's Mod Wiki

http.Fetch

http.Fetch( string url, function onSuccess = nil, function onFailure = nil, table headers = {} )

Description

Launches a GET request.

HTTP-requests to destinations on private networks (such as 192.168.0.1) won't work.
To enable HTTP-requests to destinations on private networks use Command Line Parameters -allowlocalhttp

Arguments

1 string url
The URL of the website to fetch.
2 function onSuccess = nil
Function to be called on success. Arguments are

3 function onFailure = nil
Function to be called on failure. Arguments are

  • string error - The error message
4 table headers = {}
KeyValue table for headers

Example

Shows the typical usage to get the HTML of a webpage.

local TheReturnedHTML = "" -- Blankness http.Fetch( "http://www.google.com", function( body, len, headers, code ) -- The first argument is the HTML we asked for. TheReturnedHTML = body end, function( error ) -- We failed. =( end, { -- header exemple ["accept-encoding"] = "gzip, deflate", ["accept-language"] = "fr" } )
Output: If it successfully fetched the page, the variable 'TheReturnedHTML' should contain the returned HTML in plain text.

Page Links


Special Pages


Wikis

?

Render Time: 78ms

DB GetPage 28
Generate Html 19
SaveChanges (1) 11
Render Body 0
Render Sidebar 18