Lua cURL如何获取json响应?

时间:2018-12-18 09:46:36

标签: curl lua

我使用这样的lua代码发送json帖子数据:

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字符串?

1 个答案:

答案 0 :(得分:0)

从服务器获取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)