main.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "httpdemo"
  3. VERSION = "1.0.0"
  4. --[[
  5. 本demo需要http库, 大部分能联网的设备都具有这个库
  6. http也是内置库, 无需require
  7. 1. 如需上传大文件,请使用 httpplus 库, 对应demo/httpplus
  8. 2.
  9. ]]
  10. -- sys库是标配
  11. _G.sys = require("sys")
  12. --[[特别注意, 使用http库需要下列语句]]
  13. _G.sysplus = require("sysplus")
  14. require "netready"
  15. require "test_get"
  16. require "test_post"
  17. require "test_download"
  18. require "test_fileupload"
  19. require "test_gzip"
  20. sys.taskInit(function()
  21. sys.wait(100)
  22. -------------------------------------
  23. -------- HTTP 演示代码 --------------
  24. -------------------------------------
  25. sys.waitUntil("net_ready") -- 等联网
  26. while 1 do
  27. -- 演示GET请求
  28. demo_http_get()
  29. -- 表单提交
  30. -- demo_http_post_form()
  31. -- POST一个json字符串
  32. -- demo_http_post_json()
  33. -- 上传文件, mulitform形式
  34. -- demo_http_post_file()
  35. -- 文件下载
  36. -- demo_http_download()
  37. -- gzip压缩的响应, 以和风天气为例
  38. -- demo_http_get_gzip()
  39. sys.wait(1000)
  40. -- 打印一下内存状态
  41. log.info("sys", rtos.meminfo("sys"))
  42. log.info("lua", rtos.meminfo("lua"))
  43. sys.wait(600000)
  44. end
  45. end)
  46. -- 用户代码已结束---------------------------------------------
  47. -- 结尾总是这一句
  48. sys.run()
  49. -- sys.run()之后后面不要加任何语句!!!!!