如何在 Lua 中使用 cURL 发布 json

我正在尝试在 Lua 中使用 cURL 发布 json。我在网上找不到任何示例。

类似于这样:

    c = curl.easy{
  url      = "http://posttestserver.com/post.php",
  -- url      = "http://httpbin.org/post",
  post     = true,
  httppost = curl.form{

      data = "{}",
      type = "application/json",

  },
}
t = {}
 c:perform{
        writefunction = function(s)
            t[#t+1] = s
        end
    }

c:close()
点赞
用户2328287
用户2328287

尝试这个。

local cURL = require "cURL"

c = cURL.easy{
  url        = "http://posttestserver.com/post.php",
  post       = true,
  httpheader = {
    "Content-Type: application/json";
  };
  postfields = "{}";
}

c:perform()
2017-02-09 16:30:07