转:http://blog.csdn.net/leytton/article/details/51647663
http://nodemcu-build.com/
Before we make a http-get request, connecting Wifi must be done.The demo gave by official website is as Code Block-1. See http://nodemcu.com/index_cn.html
By using php,we can get the request arguments by _GET['xxx'] directly. Demo is as Code Block-2.
Demo is as Code Block-3. We used the cjson module to parse the Json data returned by php server and iterate over and print the elements.
Since the url of NodeMcu http-get request supports Chinise badly,we can use the Base64 encoded url. For example, the base64 code of '你好' is '5L2g5aW9Cg==', then the url will be 'login.php?name=5L2g5aW9Cg=='. The php server should decode the data such as the Code Block-4.
————————————————————————————————————————
上面是练英语写作的,欢迎吐槽。中文如下:
在进行Http 的GET请求前,我们需要连接Wifi.官方给出了一个例子,代码如下
连接Wifi代码Code Block-1:
PHP服务端通过_GET['xxx']即可获取到GET请求参数。代码如下:
PHP服务端代码Code Block-2:
代码如下,我们通过cjson模块来解析PHP服务端返回的Json数据并且遍历输出。
NodeMcu进行php.get请求代码Code Block-2:
NodeMCU对GET请求的URL参数中文支持并不好,我们可以使用Base64编码后的参数。比如说"你好"的base64编码为 ”5L2g5aW9Cg==“,那么url则为 “login.php?name=5L2g5aW9Cg==”,PHP服务端对base64参数的解析代码如下:
PHP解析base64编码参数Code Block-4:
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明: NodeMCU教程 http.get请求及上传中文乱码解决方案 出自老鄢博客 | 欢迎分享