Port some examples form Lua-cURL
parent
06ca940e18
commit
5305ba55ac
|
@ -0,0 +1,18 @@
|
|||
local cURL = require("lcurl")
|
||||
|
||||
-- open output file
|
||||
f = assert(io.open("example_homepage.html", "w"))
|
||||
|
||||
cURL.easy()
|
||||
-- setup url
|
||||
:setopt_url("http://www.example.com/")
|
||||
-- setup file object as writer
|
||||
:setopt_writefunction(f)
|
||||
-- perform, invokes callbacks
|
||||
:perform()
|
||||
-- close easy
|
||||
:close()
|
||||
|
||||
-- close output file
|
||||
f:close()
|
||||
print("Done")
|
|
@ -0,0 +1,17 @@
|
|||
-- simple "On the fly" fileupload
|
||||
local cURL = require("lcurl")
|
||||
|
||||
count=0
|
||||
cURL.easy()
|
||||
:setopt_url("ftp://ftptest:secret0815@targethost/file.dat")
|
||||
:setopt_upload(true)
|
||||
:setopt_readfunction(function()
|
||||
count = count + 1
|
||||
if count < 10 then
|
||||
return "Line " .. count .. "\n"
|
||||
end
|
||||
end)
|
||||
:perform()
|
||||
:close()
|
||||
|
||||
print("Fileupload done")
|
|
@ -0,0 +1,15 @@
|
|||
local cURL = require("lcurl")
|
||||
|
||||
local post = cURL.form()
|
||||
-- post file from filesystem
|
||||
:add_file ("name", "post.lua", "text/plain")
|
||||
-- post file from data variable
|
||||
:add_buffer("name2", "dummy.html", "<html><bold>bold</bold></html>", "text/html")
|
||||
|
||||
cURL.easy()
|
||||
:setopt_url("http://localhost")
|
||||
:setopt_httppost(post)
|
||||
:perform()
|
||||
:close()
|
||||
|
||||
print("Done")
|
|
@ -0,0 +1,23 @@
|
|||
-- Cookie data will be shared across the easy handles to do an authorized download
|
||||
local cURL = require("lcurl")
|
||||
|
||||
-- create share handle (share COOKIE and DNS Cache)
|
||||
s = cURL.share()
|
||||
:setopt_share(cURL.LOCK_DATA_COOKIE )
|
||||
:setopt_share(cURL.LOCK_DATA_DNS )
|
||||
|
||||
-- create first easy handle to do the login
|
||||
c = cURL.easy()
|
||||
:setopt_share(s)
|
||||
:setopt_url("http://targethost/login.php?username=foo&password=bar")
|
||||
|
||||
-- create second easy handle to do the download
|
||||
c2 = cURL.easy()
|
||||
:setopt_share(s)
|
||||
:setopt_url("http://targethost/download.php?id=test")
|
||||
|
||||
-- login
|
||||
c:perform()
|
||||
|
||||
-- download
|
||||
c2:perform()
|
Loading…
Reference in New Issue