Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local curl = require "cURL"
- local function data_writer(context, data)
- table.insert(context, data)
- return #data
- end
- local function print_response(easy, context)
- local code = easy:getinfo_response_code()
- local body = table.concat(context)
- print(code .. "\r\n" .. body)
- end
- local function clear_context(context)
- count = #context
- for i = 0, count do context[i] = nil end
- end
- local function main()
- local tmp = {}
- local e = curl.easy()
- -- e:setopt_verbose(true)
- e:setopt_writefunction(data_writer, tmp)
- e:setopt_url("https://httpbin.org/get")
- clear_context(tmp) -- !!!
- assert(e:perform())
- print_response(e, tmp)
- -- e:setopt_forbid_reuse(true)
- e:setopt_url("https://httpbin.org/ip")
- clear_context(tmp) -- !!!
- assert(e:perform())
- print_response(e, tmp)
- e:close()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment