我能用 Lua 脚本请求 http API 吗?

以下是我从其他帖子学习到的示例代码:

-- test.lua
function get(url)
    local handle = io.popen("curl -q -k -s -m l"..url)
    local result = handle:read("*a")
    handle:close()
    return result
end

local result = get("http://headers.jsontest.com/");

alert(result);

我在 Cydia iPhone6 中安装了 cUrl。当我在 AutoTouch 上运行这个 test.lua 时,没有错误日志,但没有打印任何内容...

  1. 我如何使用 Lua 成功进行 http 请求?

  2. 如何对响应的 JSON 数据进行编码和解码循环?

  3. 我能使用 print() 输出吗?或者我只能在 iPhone 上使用 log() 和 alert() 来调试 Lua 脚本?

谢谢你的帮助!

点赞