--!movie
--!encoding=utf-8
global $
----------------------------------------
-- Send data and files with HTTP POST (multipart/form-data-encoding)
-- (synchronous or blocking mode)
----------------------------------------
on startMovie
_player.debugPlaybackEnabled = 1
-- libs
$.import("curl")
-- get a CURL handle (xtra instance)
ch = $.curl.init()
-- specify options
ch.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/echo.php")
--ch.setOption($.curl.CURLOPT.POST, 1) -- not required, POST automatically used when form data is assigned
-- create a form list
form = []
-- add a POST variable
section = [:]
section.addProp($.curl.CURLFORM.COPYNAME, "foo")
section.addProp($.curl.CURLFORM.COPYCONTENTS, "äöü")
form.add(section)
-- add another POST variable
section = [:]
section.addProp($.curl.CURLFORM.COPYNAME, "bar")
section.addProp($.curl.CURLFORM.COPYCONTENTS, "hello world")
form.add(section)
-- add a FILE upload
section = [:]
section.addProp($.curl.CURLFORM.COPYNAME, "file1")
section.addProp($.curl.CURLFORM.FILE, $.PATH & "http_get.lsw")
form.add(section)
-- add another FILE
section = [:]
section.addProp($.curl.CURLFORM.COPYNAME, "file2")
section.addProp($.curl.CURLFORM.FILE, $.PATH & "http_post.lsw")
form.add(section)
ch.setForm(form)
-- returnMode: 0=return error code (=default), 1=return data
res = ch.exec(1)
if integerP(res) then
put "ERROR:" && curl_error(res)
else
put "RESULT:" && res.readRawString(res.length)
-- put "SPEED_UPLOAD:" && ch.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
-- put "SPEED_DOWNLOAD:" && ch.getInfo($.curl.CURLINFO.SPEED_DOWNLOAD)
-- put "TOTAL_TIME:" && ch.getInfo($.curl.CURLINFO.TOTAL_TIME)
end if
end