Menu

Use Case

djfdyuruiry

Below is a sample use case for HttpRequester, it is written in Lua script but comments should allow anyone unfamiliar to follow along.

JSON = (loadfile "JSON.lua")()

-- Command line args for HttpRequester.
local args = "\"{'Url':'http://www.google.co.uk','HttpMethod':'GET'}\""

-- Start HttpRequester and read all output
local httpRequester = io.popen("HttpRequester.exe " .. args)
local responseObj = ""

for line in httpRequester:lines() do
responseObj = responseObj .. line
end

-- Decode JSON response object.
local responseObj = JSON:decode(responseObj)

-- Check for error then print response body to html file.
if responseObj.Error == nil then
local file = assert(io.open("google.html", "w"))
    file:write(responseObj.ResponseBody)
    file:close()
end




I used to process standard output re-director here but you could just as easily do 'HttpRequester "..." > someTempFile.temp', then read the file contents and delete it.

An aside here is that I use a JSON library for Lua, http://regex.info/blog/lua/json, but you do not require a JSON library to use this tool, one could parse the output manually using any standard string library.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.