main.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "httpdemo"
  3. VERSION = "1.0.0"
  4. _G.sys = require("sys")
  5. require "sysplus"
  6. sys.taskInit(function()
  7. sys.waitUntil("IP_READY")
  8. local code, headers, body = http.request("GET", "https://httpbin.air32.cn/get").wait()
  9. log.info("http", code, json.encode(headers), body)
  10. -- local code, headers, body = http.request("POST", "http://ql.betterforyou.com.cn:9090/ck/app/appUpgrade/findMiniUpgrade?equId=QL10000001&equType=1").wait()
  11. -- log.info("http.get", code, headers, body)
  12. log.info("GoGoGo")
  13. sys.wait(1000)
  14. local body = io.readFile("/luadb/wifi.json")
  15. local code, headers, body = http.request("POST", "http://wifi.air32.cn/wifi", nil, body).wait()
  16. log.info("http", code, json.encode(headers), #body)
  17. -- log.info("http", "body", #body)
  18. -- log.info("http", "body", body)
  19. socket.sslLog(5)
  20. local httpplus = require "httpplus"
  21. -- local code, resp = httpplus.request({url="https://vaviri-back-ph4lj.ondigitalocean.app/state"})
  22. local code, resp = httpplus.request({
  23. url="http://wifi.air32.cn/wifi",
  24. body=io.readFile("/luadb/wifi.json"),
  25. headers={"Content-Type", "application/json"},
  26. method="POST"}
  27. )
  28. local body = resp.body:query()
  29. -- log.info("http", code, json.encode(resp.headers), #body)
  30. log.info("http2", "body", #body)
  31. log.info("http2", "body", body)
  32. log.info("http2", "body", body:toHex())
  33. -- body = io.readFile("/luadb/gzip")
  34. -- log.info("gzip", #body)
  35. -- -- log.info("http", miniz.uncompress(body:sub(11)))
  36. -- log.info("http", miniz.uncompress(body:sub(11), 0))
  37. -- log.info("http", body:toHex())
  38. local code, headers, body = http.request("GET", "http://httpbin.air32.cn/range/1024", nil, nil, {debug=false}).wait()
  39. log.info("http3", code, json.encode(headers), body)
  40. local code, headers = http.request("GET", "http://httpbin.air32.cn/stream-bytes/20", nil, nil, {debug=true}).wait()
  41. log.info("http4", code, headers, body)
  42. end)
  43. sys.run()