1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gCh
  7.  
  8. ----------------------------------------
  9. -- Send data and files with HTTP POST (multipart/form-data-encoding)
  10. -- (synchronous or blocking mode)
  11. ----------------------------------------
  12. on startMovie
  13.     _player.debugPlaybackEnabled = 1
  14.  
  15.     -- libs
  16.     $.import("curl")
  17.  
  18.     -- get a CURL handle (xtra instance)
  19.     gCh = $.curl.init()
  20.  
  21.     -- specify options
  22.     gCh.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/echo.php")
  23.     --gCh.setOption($.curl.CURLOPT.POST, 1) -- not required, POST automatically used when form data is assigned
  24.     gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
  25.  
  26.     -- create a form list
  27.     form = []
  28.  
  29.     -- add a POST variable
  30.     section = [:]
  31.     section.addProp($.curl.CURLFORM.COPYNAME, "foo")
  32.     section.addProp($.curl.CURLFORM.COPYCONTENTS, "äöü")
  33.     form.add(section)
  34.  
  35.     -- add another POST variable
  36.     section = [:]
  37.     section.addProp($.curl.CURLFORM.COPYNAME, "bar")
  38.     section.addProp($.curl.CURLFORM.COPYCONTENTS, "hello world")
  39.     form.add(section)
  40.  
  41.     -- add a FILE upload
  42.     section = [:]
  43.     section.addProp($.curl.CURLFORM.COPYNAME, "file1")
  44.     section.addProp($.curl.CURLFORM.FILE, $.PATH & "http_get.lsw")
  45.     form.add(section)
  46.  
  47.     -- add another FILE
  48.     section = [:]
  49.     section.addProp($.curl.CURLFORM.COPYNAME, "file2")
  50.     section.addProp($.curl.CURLFORM.FILE, $.PATH & "test.mp3")
  51.     form.add(section)
  52.  
  53.     gCh.setForm(form)
  54.  
  55.     gCh.setProgressCallback(#slotCurlProgress)
  56.  
  57.     -- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
  58.     $.curl.execAsyncDetached(gCh, #slotCurlResult, _movie, 1)
  59.  
  60. end
  61.  
  62. ----------------------------------------
  63. -- @callback
  64. ----------------------------------------
  65. on slotCurlResult (res)
  66.     if integerP(res) then
  67.         put "ERROR:" && curl_error(res)
  68.     else
  69.         put "RESULT:" && res.readRawString(res.length)
  70. --      put "SPEED_UPLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
  71. --      put "SPEED_DOWNLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_DOWNLOAD)
  72. --      put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
  73.     end if
  74.     gCh = VOID
  75. end
  76.  
  77. ----------------------------------------
  78. -- @callback
  79. ----------------------------------------
  80. on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
  81.     -- put dltotal, dlnow, ultotal, ulnow
  82.     if ultotal>0 then
  83.         put (ulnow*100/ultotal) && "%"
  84.     end if
  85. end
  86.  
[raw code]