Http 带Lua的基本CGI
我需要一个非常轻量级的web解决方案来在Linux设备上运行,以处理HTML表单,因此打算使用和Lua 在CGI脚本中,使用以下代码:Http 带Lua的基本CGI,http,lua,cgi,uwsgi,Http,Lua,Cgi,Uwsgi,我需要一个非常轻量级的web解决方案来在Linux设备上运行,以处理HTML表单,因此打算使用和Lua 在CGI脚本中,使用以下代码: print ("Content-type: Text/html\n") print ("Hello, world!") 然而,这也起作用: print("Status: 200 OK\r\n\r\nHello, world!\r\n") 我想知道返回web服务器真正需要什么CGI脚本 谢谢。 根本不需要一个头,你真正需要的是结束标题并开始正文的空白行: pr
print ("Content-type: Text/html\n")
print ("Hello, world!")
然而,这也起作用:
print("Status: 200 OK\r\n\r\nHello, world!\r\n")
我想知道返回web服务器真正需要什么CGI脚本
谢谢。
根本不需要一个头,你真正需要的是结束标题并开始正文的空白行:print ("\nHello, World")
也应该有效
但是,您至少应该包括包含字符集的内容类型,因为浏览器应默认为iso-8859-1,但用户可能会覆盖此设置,并且您应该使用utf-8以避免在可以显示的字符中受到限制
print("Content-type: text/html; charset=utf-8")
另外,如果您正在编程一个设备,您可能希望避免缓存,所以我会额外花费一笔钱
print("Cache-control: no-cache")
print("Pragma: no-cache")
这会阻止浏览器和代理缓存您的页面。但是您需要处理HTML表单数据(比如POST数据)。您可以使用Ajax表单(javascript库)的强大功能将POST数据作为JSON发送,您可以使用io:read(“*”)将其读取回Lua脚本。感谢Guntram提供的信息。您最好使用
io.write
来完全控制输出,因为print
添加了选项卡和换行符。