【问题标题】:Lua cURL how to get json response?Lua cURL如何获得json响应?
【发布时间】:2019-01-23 17:39:32
【问题描述】:

我使用这样的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字符串?

【问题讨论】:

  • 没用过lua-curl,但是阅读manual 3 分钟建议添加writefunction 就可以了。

标签: curl lua


【解决方案1】:

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

【讨论】:

  • 这种语言很糟糕,它依赖于其他社区包。
猜你喜欢
  • 2018-02-01
  • 2023-01-29
  • 1970-01-01
  • 2020-12-13
  • 2011-04-27
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 2018-10-30
相关资源
最近更新 更多