我正在尝试使用 ucspi-tcp 中的 tcpserver 来启动一个返回简单网页的脚本。我的脚本(hello.lua)如下:
#!/usr/bin/env lua
print([[HTTP/1.1 200 OK
Content-Type: text/html
<html>
<head>
<title>My title</title>
</head>
<body>
<h1>Hello in big font</h1>
</body>
</html>]])
我启动它 tcpserver -v -rh 0 9000 /path/to/hello.lua
当我使用时tcpcat myserver 9000,我得到了预期的回报:
HTTP/1.1 200 OK
Content-Type: text/html
<html>
<head>
<title>My title</title>
</head>
<body>
<h1> Hello in big font</h1>
</body>
</html>
但是,当我尝试使用网络浏览器并指向 时,即使 tcpserver 日志记录显示事务http:\\myserver:9000,我Error 101 (net::ERR_CONNECTION_RESET): Unknown error也会收到浏览器错误(在 Chrome 中):
tcpserver: status 1/40
tcpserver: pid 21672 from <ip address of browser>
tcpserver: ok 21672 <server hostname>::::ffff:<server ip>:9000 <client hostname>::::ffff:<client ip>::3133
tcpserver: end 21672 status 0
我知道我在这里遗漏了一些基本的东西,但我不能把拼图的各个部分放在一起。任何见解表示赞赏!谢谢!
标题和内容之间需要一个空行:
HTTP/1.1 200 OK
Content-Type: text/html
<html>
<head>
<title>My title</title>
</head>
<body>
<h1>Hello in big font</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1075 次 |
| 最近记录: |