我对 LUA 很陌生,我正在尝试使用 LUA 从我的 ESP8266 向我的本地主机上的 PHP 服务器发送一个 json 帖子,我搜索了互联网,但我找不到任何示例可以帮助我吗?
我的 LUA 代码
-- tested on NodeMCU 0.9.5 build 20141222...20150108
-- sends connection time and heap size to http:server.php
wifi.setmode(wifi.STATION)
wifi.sta.config("VIVA-4G-LTE-6134","VIVA176429")
--wifi.sta.config("AndroidAP","rapz4736")
print('httpget.lua started')
Tstart = tmr.now()
conn = nil
conn = net.createConnection(net.TCP, 0)
-- show the retrieved web page
conn:on("receive", function(conn, payload)
success = true
print(payload)
end)
-- once connected, request page (send parameters to a php script)
conn:on("connection", function(conn, payload)
print('\nConnected')
conn:send("POST /server.php?"
.."name=mometto"
.."&age=27"
.." HTTP/1.1\r\n"
.."Host: 172.0.0.1\r\n"
.."Connection: close\r\n"
.."Accept: */*\r\n"
.."User-Agent: Mozilla/4.0 "
.."(compatible; esp8266 Lua; "
.."Windows NT 5.1)\r\n"
.."\r\n")
-- conn:send("what":"books", "count":3 )
end)
-- when disconnected, let it be known
conn:on("disconnection", function(conn, payload) print('\nDisconnected') end)
conn:connect(80,'192.168.43.181')
在这里发送参数对我来说很容易,但是当我想发送请求正文时我不能,我尝试添加此代码来发送请求正文
conn:send("what":"books", "count":3 )
那么任何人都可以为我提供任何帮助吗?