esp8266在lua中发送json请求正文

时间:2015-11-07 05:00:52

标签: php json lua esp8266

我是lua的新手,我正试图从我的ESP8266发送一个json帖子,使用lua到我本地主机上的PHP服务器,我搜索了互联网,我找不到任何一个例子可以做任何一个帮助我好吗?

我的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 )

但它没有用,我收到了这条消息:

  

enter image description here

那么任何人都能为我提供任何帮助吗?

0 个答案:

没有答案
相关问题