mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-30 21:12:55 +08:00
parent
2e16e3af5f
commit
08921c9871
40
lua_examples/http-client.lua
Normal file
40
lua_examples/http-client.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
-- Support HTTP and HTTPS, For example
|
||||||
|
-- HTTP POST Example with JSON header and body
|
||||||
|
http.post("http://somewhere.acceptjson.com/",
|
||||||
|
"Content-Type: application/json\r\n",
|
||||||
|
"{\"hello\":\"world\"}",
|
||||||
|
function(code, data)
|
||||||
|
print(code)
|
||||||
|
print(data)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- HTTPS GET Example with NULL header
|
||||||
|
http.get("https://www.vowstar.com/nodemcu/","",
|
||||||
|
function(code, data)
|
||||||
|
print(code)
|
||||||
|
print(data)
|
||||||
|
end)
|
||||||
|
-- You will get
|
||||||
|
-- > 200
|
||||||
|
-- hello nodemcu
|
||||||
|
|
||||||
|
-- HTTPS DELETE Example with NULL header and body
|
||||||
|
http.delete("https://10.0.0.2:443","","",
|
||||||
|
function(code, data)
|
||||||
|
print(code)
|
||||||
|
print(data)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- HTTPS PUT Example with NULL header and body
|
||||||
|
http.put("https://testput.somewhere/somewhereyouput.php","","",
|
||||||
|
function(code, data)
|
||||||
|
print(code)
|
||||||
|
print(data)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- HTTP RAW Request Example, use more HTTP/HTTPS request method
|
||||||
|
http.request("http://www.apple.com:80/library/test/success.html","GET","","",
|
||||||
|
function(code, data)
|
||||||
|
print(code)
|
||||||
|
print(data)
|
||||||
|
end)
|
Loading…
x
Reference in New Issue
Block a user