在lua脚本中使用curl发送消息给slack



当尝试在LUA中使用curl向slack发送消息时,我得到了这个脚本的错误。谢谢你的帮助。

cmd="c:\curl\bin\curl.exe -X POST -H "Content-type: application/json" -d "{"text":"Hello"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx"

LUA_ERROR:[string "cmd="c:curlbincurl.exe - x POST - h "Content-type: applicat…"]:1:=' expected near-'

您的脚本充满了语法错误,因为您没有转义包含cURL命令参数的双引号。最简单的解决方案是在这里使用长字符串,不需要转义双引号,而不将"解释为",从而保留内部转义:

cmd=[[c:curlbincurl.exe -X POST -H "Content-type: application/json" -d "{"text":"Hello"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx]]

或者您可以使用单引号,要求转义所有反斜杠:

cmd='c:\curl\bin\curl.exe -X POST -H "Content-type: application/json" -d "{\"text\":\"Hello\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx'

最新更新