0

I'm trying to post json in Lua using cURL. I can't find any example online.

Something like this:

    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()

1 Answer 1

2

Try this one.

local cURL = require "cURL"

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

c:perform()
Sign up to request clarification or add additional context in comments.

4 Comments

I think I need add this to examples :)
Good idea, it might help somebody to save couple hours. ;) Anyway, thank you a lot! You are awesome!
Maybe you can show how I can return 200 for ok and error code if something went wrong? Still can't figure it out. Thank you in advance!
You can use c:getinfo_response_code() after perform. You can find all avaliable option in official documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.