Lua cURL如何获取JSON响应?

我使用以下Lua代码发送JSON POST数据:

local cURL = require("cURL")
local request = cURL.easy{
   url        = "http://myurl",
   post       = true,
   httpheader = { "Content-Type: application/json"; },
   postfields = jsonString,
   timeout = 1
}

request:perform()

如何获取响应JSON字符串?

点赞
用户6679321
用户6679321

从服务器获取 JSON 响应最简单的方式是:

local http = require("socket.http")
local cjson = require("cjson")
local requesrString = "http://hostname/path?params"
local body, code = http.request(requesrString)
local jsonDict = cjson.decode(body)
2019-01-23 09:39:32