在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Lua-cURL/Lua-cURLv3开源软件地址(OpenSource Url):https://github.com/Lua-cURL/Lua-cURLv3开源编程语言(OpenSource Language):C 59.0%开源软件介绍(OpenSource Introduction):libcurlLua binding toStatusThis module include three layer
Documentationlcurl API Original Lua-cURLv2 binding has several problems:
InstallationUsing LuaRocks:
Install current master:
Lua-cURLv2List of incompatibility with original
Usage-- HTTP Get
curl.easy{
url = 'http://httpbin.org/get',
httpheader = {
"X-Test-Header1: Header-Data1",
"X-Test-Header2: Header-Data2",
},
writefunction = io.stderr -- use io.stderr:write()
}
:perform()
:close() -- HTTP Post
curl.easy()
:setopt_url('http://posttestserver.com/post.php')
:setopt_writefunction(io.write)
:setopt_httppost(curl.form() -- Lua-cURL guarantee that form will be alive
:add_content("test_content", "some data", {
"MyHeader: SomeValue"
})
:add_buffer("test_file", "filename", "text data", "text/plain", {
"Description: my file description"
})
:add_file("test_file2", "BuildLog.htm", "application/octet-stream", {
"Description: my file description"
})
)
:perform()
:close() -- FTP Upload
local function get_bin_by(str,n)
local pos = 1 - n
return function()
pos = pos + n
return (str:sub(pos,pos+n-1))
end
end
curl.easy()
:setopt_url("ftp://moteus:[email protected]/test.dat")
:setopt_upload(true)
:setopt_readfunction(
get_bin_by(("0123456789"):rep(4), 9)
)
:perform()
:close() -- Multi FTP Upload
-- We get error E_LOGIN_DENIED for this operation
e1 = curl.easy{url = "ftp://moteus:[email protected]/test1.dat", upload = true}
:setopt_readfunction(
function(t) return table.remove(t) end, {"1111", "2222"}
)
e2 = curl.easy{url = "ftp://moteus:[email protected]/test2.dat", upload = true}
:setopt_readfunction(get_bin_by(("e"):rep(1000), 5))
m = curl.multi()
m:add_handle(e1)
m:add_handle(e2)
while m:perform() > 0 do m:wait() end
while true do
h, ok, err = m:info_read()
if h == 0 then break end
if h == e1 then
assert(ok == nil)
assert(err:name() == "LOGIN_DENIED")
assert(err:no() == curl.E_LOGIN_DENIED)
end
if h == e2 then
assert(ok == true)
end
end |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论