- Posts: 47
- Joined: Thu Aug 23, 2012 8:53 pm
I'm trying to use the resolve API with Lua to log into a REST API interface (Airtable in this case). However when I use the HTTP headers in this line:
The code stalls. I've never had that in a Lua script before. If you remove that line the script functions. But the ability to pass an authorisation key etc is lost. The below code sends headers to test website: http://httpbin.org/headers which posts any headers sent to it. Currently it stalls. But sending a CURL command from the command line will work. This implies that there is an issue with Resolves Lua implementation. Anyone have any ideas on how to get around this?
- Code: Select all
req:setOption(curl.CURLOPT_HTTPHEADER, headerStr)
The code stalls. I've never had that in a Lua script before. If you remove that line the script functions. But the ability to pass an authorisation key etc is lost. The below code sends headers to test website: http://httpbin.org/headers which posts any headers sent to it. Currently it stalls. But sending a CURL command from the command line will work. This implies that there is an issue with Resolves Lua implementation. Anyone have any ideas on how to get around this?
- Code: Select all
function testHttpbinHeaders()
print("Starting testHttpbinHeaders function")
local sourceURL = "http://httpbin.org/headers"
print("Constructed sourceURL: " .. sourceURL)
local ffi = require "ffi"
local curl = require "lj2curl"
local ezreq = require "lj2curl.CRLEasyRequest"
local req = ezreq(sourceURL)
local body = {}
req:setOption(curl.CURLOPT_SSL_VERIFYPEER, 0)
req:setOption(curl.CURLOPT_WRITEFUNCTION, ffi.cast("curl_write_callback",
function(buffer, size, nitems, userdata)
table.insert(body, ffi.string(buffer, size * nitems))
return nitems
end))
print("Setting up headers")
local headerStr = "Test-Header: TestValue"
req:setOption(curl.CURLOPT_HTTPHEADER, headerStr)
print("Performing request")
local ok, err = req:perform()
print("Request status: " .. tostring(ok))
print("Error (if any): " .. tostring(err))
if not ok then
print("Error performing request: " .. tostring(err))
return nil
end
print("Request performed successfully")
local responseBody = table.concat(body)
print("Response body: " .. responseBody)
return responseBody
end
testHttpbinHeaders()