如何使用cURL在lua中发布json

kwvwclae  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(205)

我尝试用cURL在Lua中发布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()
lmvvr0a8

lmvvr0a81#

试试这个

local cURL = require "cURL"

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

c:perform()

相关问题