--!movie
--!encoding=utf-8
global $
global gCh
----------------------------------------
-- 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)
gCh = $.curl.init()
-- specify options
gCh.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/echo.php")
--gCh.setOption($.curl.CURLOPT.POST, 1) -- not required, POST automatically used when form data is assigned
gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
-- 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 & "test.mp3")
form.add(section)
gCh.setForm(form)
gCh.setProgressCallback(#slotCurlProgress)
-- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
$.curl.execAsyncDetached(gCh, #slotCurlResult, _movie, 1)
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlResult (res)
if integerP(res) then
put "ERROR:" && curl_error(res)
else
put "RESULT:" && res.readRawString(res.length)
-- put "SPEED_UPLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
-- put "SPEED_DOWNLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_DOWNLOAD)
-- put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
end if
gCh = VOID
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
-- put dltotal, dlnow, ultotal, ulnow
if ultotal>0 then
put (ulnow*100/ultotal) && "%"
end if
end