使用 Node.js 从零开始构建你自己的 Web 服务器
来源请点击
二 HTTP 概述
2.1 概述
http请求或响应都有一个头部和一个可选的payload组成。头部包含URL或响应码,后跟一个头部字段列表。
2.2 示例
netcat命令
nc baidu.com 80
nc(netcat)命令会创建一个到目标主机和端口的 TCP 连接,然后将该连接附加到标准输入和标准输出。
然后输入
@111 ~ % nc example.com 80
GET / HTTP/1.0
Host:example.com
(空行)
会看到输出:
HTTP/1.0 200 OK
Accept-Ranges: bytes
Content-Type: text/html
ETag: "bc2473a18e003bdb249eba5ce893033f:1760028122.592274"
Last-Modified: Thu, 09 Oct 2025 16:42:02 GMT
Content-Length: 513
Cache-Control: max-age=86000
Date: Sun, 07 Dec 2025 10:24:34 GMT
Connection: close
<!doctype html><html lang="en"><head><title>Example Domain</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}Example Domain
This domain is for use in documentation examples without needing permission. Avoid use in operations.
Learn more

