Revision Difference
http.Fetch#516760
<function name="Fetch" parent="http" type="libraryfunc">
<description>Launches a GET request.</description>
<realm>Shared and Menu</realm>
<file line="18-L44">lua/includes/modules/http.lua</file>
<args>
<arg name="url" type="string">The URL of the website to fetch.</arg>
<arg name="onSuccess" type="function">Function to be called on success. Arguments are
* {{FuncArg|string|body</arg>⤶
<arg name="onFailure" type="function" default="nil">Function to be called on failure. Arguments are
* <page>string</page> error - The error message</arg>
<arg name="headers" type="table" default="{}">KeyValue table for headers</arg>
</args>
</function>
⤶
* <page>string</page> size - equal to <page>string.len(body)</page>⤶
* <funcarg|table|headers}}⤶
⤶
<arg⤶
|type=function⤶
|name=onsuccess⤶
|desc=function to be called on success. arguments are⤶
* {{funcarg|string|body}}⤶
* <page>string</page> size - equal to <page>string.len(body)</page>⤶
* {{funcarg|table|headers}}⤶
* <page>number</page> code - the http success code>
<default>nil</default>
⤶
</funcarg|table|headers}}⤶
⤶
</arg⤶
|type=function⤶
|name=onsuccess⤶
|desc=function to be called on success. arguments are⤶
* {{funcarg|string|body}}⤶
* <page>string</page> size - equal to <page>string.len(body)</page>⤶
* {{funcarg|table|headers}}⤶
* <page>number</page> code - the http success code>
<example>
<description>Shows the typical usage to get the HTML of a webpage.</description>
<code>
local TheReturnedHTML = "" -- Blankness
http.Fetch( "http:&#47;&#47;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
)
</code>
<output>If it successfully fetched the page, the variable 'TheReturnedHTML' should contain the returned HTML in plain text.</output>
</example>