如何从发送到NodeMCU的lua中的http请求中获取post参数 [英] How to get post parameters from http request in lua sent to NodeMCU

查看:29
本文介绍了如何从发送到NodeMCU的lua中的http请求中获取post参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 Tasker(Android 应用程序)将此 HTTP POST 请求发送到我的 NodeMCU,如下所示:

I sent this HTTP POST request via Tasker (Android app) to my NodeMCU, which looks like this:

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: Tasker/4.9u4m (Android/6.0.1)
Connection: close
Content-Length: 10
Host: 192.168.0.22
Accept-Encoding: gzip

<action>Play</action><SetVolume>5</SetVolume>

我只想提取"之间的内容和"参数.我该怎么做?

I only want to extract what is between the "<action>" and "<SetVolume>" parameters. How can I do that?

推荐答案

为了完整起见,这里是我想出的另一个解决方案:

For the sake of completeness, here is another solution I came up with:

string.gsub(request, "<(%a+)>([^<]+)</%a+>", function(key, val)
  print(key .. ": " .. val)
end)

可以在此处查看在您的问题中使用给定 HTTP 请求的工作示例:

A working example using the given HTTP request in your question can be seen here:

https://repl.it/repls/GlamorousAnnualConferences

这篇关于如何从发送到NodeMCU的lua中的http请求中获取post参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆