get

Top  Previous  Next

This function does a standard HTTP get call on the URL provided optionally with a username and password. The result is passed back into the callback function.

Definition

network.get( url, callback, timeout, username, password, headers )

 

Name

Type

Description

url

string

Fully qualified URL. For example HTTP://www.promixis.com

callback

function

The function to be called with the result.

timeout

number

Timeout for operation in ms

username [optional]

string

Username to use in authentication.

password [optional]

string

Password to use in authentication.

headers [optional]

table of strings

Headers to send with request. Each string must be of the form HEADER: Value. For example {"Agent: Girder", "FakeHeader": "FakeValue"}

Callback function signature

function ( success, status, body )

 

Name

Type

Description

success

boolean

Returns true if the HTTP call was successful. Note that this could still mean the status code is not 200 ( = HTTP OK ).

status

number

HTTP Status code. 200 = OK.

body

string

The body of the response.

Example

network.get( "http://www.promixis.com", function ( success, status, body )

 

if not success then

 print("Sorry could not connect with server")

 return

end

 

if status ~= 200 then

 print("Sorry server returned", status)

 return

end

 

print(body)

 

end, 3000)

 

Returns the content of the Promixis home page, which starts with something like <html><head>...

Related

post

Availability

Lua