http.Fetch

From Garry's Mod
Jump to: navigation, search
 http.Fetch( )

Contents

Description

Launches a GET request.

Arguments

string url

The URL of the website to fetch.

Arguments

function onSuccess=nil

Function to be called on success. Arguments are

Arguments

function onFailure=nil

Function to be called on failure. Arguments are

  • string error - The error message

Arguments

table headers={}

KeyValue table for headers

Examples

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
)

Output:

If it successfully fetched the page, the variable 'TheReturnedHTML' should contain the returned HTML in plain text.
Personal tools
Navigation