Request

This page explains how to initiate custom HTTP connections using Lua script that are logged to the Sandcat Live Headers.

Loading or sending a custom HTTP request

Example


myheaders = [[
X-MyHeader: AValue
]]

-- GET example
tab:sendrequest{
 method = 'GET',
 url = 'http://www.somehost.com/',
 headers = myheaders,
 usecookies = false
}

-- POST example
tab:sendrequest{
 method = 'POST',
 url = tab.url..'/somepath',
 postdata = 'id=1'
}

If you want to load the request using the browser, just replace the sendrequest() method with loadrequest()

Keys

The following keys can be provided:
method - the HTTP method (GET, POST, etc). Default GET
url - the request URL (if not supplied, the tab URL will be used as URL)
postdata - the request data
headers - custom request headers
ignorecache - If supplied, and is false, may load the page from the cache. Default true.
useauth - If supplied, and is true, uses cached authentication credentials. Default true.
usecookies - If supplied, and is false, ignores cookies. Default true.
details - a short description for the request

Logging a request from a custom HTTP client class

Example

This one uses the Selenite's httprequest class, included with Sandcat 4:


http = scl.httprequest:new()
http:open('GET','http://www.somehost.com/')
if http.status == 200 then
  -- the requestinfo property returns a compatible JSON object with the required keys.
 tab:logrequest(http.requestinfo)
end
http:release()

Keys

The following keys can be provided:
method (required) - the request method
url (required) - the request URL. In case this is a low level request you can supply a host and a port key instead of an URL key.
postdata - the request data
headers - the request headers
responseheaders - the response headers
responsefilename - the name of a temporary file that must contain the response text or stream. The file will be automatically deleted after its contents are added to the Live Headers cache.
status - if not supplied, the status code will be read from the response headers
details - a short description for the request
Page last modified on October 23, 2015, at 10:52 PM
2013 Syhunt