http-client.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -- Support HTTP and HTTPS, For example
  2. -- HTTP POST Example with JSON header and body
  3. http.post("http://somewhere.acceptjson.com/",
  4. "Content-Type: application/json\r\n",
  5. "{\"hello\":\"world\"}",
  6. function(code, data)
  7. print(code)
  8. print(data)
  9. end)
  10. -- HTTPS GET Example with NULL header
  11. http.get("https://www.vowstar.com/nodemcu/","",
  12. function(code, data)
  13. print(code)
  14. print(data)
  15. end)
  16. -- You will get
  17. -- > 200
  18. -- hello nodemcu
  19. -- HTTPS DELETE Example with NULL header and body
  20. http.delete("https://10.0.0.2:443","","",
  21. function(code, data)
  22. print(code)
  23. print(data)
  24. end)
  25. -- HTTPS PUT Example with NULL header and body
  26. http.put("https://testput.somewhere/somewhereyouput.php","","",
  27. function(code, data)
  28. print(code)
  29. print(data)
  30. end)
  31. -- HTTP RAW Request Example, use more HTTP/HTTPS request method
  32. http.request("http://www.apple.com:80/library/test/success.html","GET","","",
  33. function(code, data)
  34. print(code)
  35. print(data)
  36. end)