Go to file
Alexey Melnichuk de4e4ccb30 Fix. Echo libcurl version in test. 2014-08-26 13:53:45 +05:00
.travis Add. Travis files 2014-08-26 12:40:18 +05:00
doc Add. Travis files 2014-08-26 12:40:18 +05:00
examples Add. Easy wrapper example 2014-08-25 16:31:41 +05:00
msvc Move error codes in separate files. 2014-08-26 13:47:20 +05:00
rockspecs Add. Travis files 2014-08-26 12:40:18 +05:00
src Move error codes in separate files. 2014-08-26 13:47:20 +05:00
test Fix. Echo libcurl version in test. 2014-08-26 13:53:45 +05:00
.gitignore Fix. Support libcurl >= 7.25 2014-08-26 13:28:34 +05:00
.travis.yml Fix. Support libcurl >= 7.25 2014-08-26 13:28:34 +05:00
LICENSE Initial commit 2014-08-25 14:00:15 +05:00
README.md Init commit 2014-08-25 13:12:45 +05:00

README.md

Lua binding to libcurl

Usage

-- HTTP Get
curl:easy()
  :setopt_url('http://httpbin.org/get')
  :setopt_httpheader{
    "X-Test-Header1: Header-Data1",
    "X-Test-Header2: Header-Data2",
  }
  :setopt_writefunction(io.stderr)
  :perform()
:close()
-- HTTP Post
curl:easy()
  :setopt_url('http://posttestserver.com/post.php')
  :setopt_writefunction(io.write)
  :setopt_httppost(curl.httppost()
    :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:123456@127.0.0.1/test.dat")
  :setopt_upload(true)
  :setopt_readfunction(
    get_bin_by(("0123456789"):rep(4), 9)
  )
  :perform()
:close()