nc 收到时的 HTTP 错误响应

HTTP incorrect response when that received by nc

当我收到带有 nc 命令的 HTTP 响应时,结果不正确。 例如

$nc site.it 80
GET / HTTP/1.1
Host: site.it
User-Agent: curl/7.54.0
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 13 Apr 2018 07:34:31 GMT
Server: Apache/2.4.29 (Debian)
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8

17b
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Index of /</title>

但是当我使用 curl 命令时结果是

$curl -v site.it
* Rebuilt URL to: site.it/
*   Trying 1.2.3.4...
* TCP_NODELAY set
* Connected to site.it (1.2.3.4) port 80 (#0)
> GET / HTTP/1.1
> Host: site.it
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 13 Apr 2018 07:39:44 GMT
< Server: Apache/2.4.29 (Debian)
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html;charset=UTF-8
< 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Index of /</title>

在这种情况下,使用 nc 命令的第一个请求有一个额外的字符 17b,它对页面的真实来源不可用。
有人能告诉我为什么会这样吗?

因为响应是使用Transfer-Encoding: chunked发回的,所以17b是第一个数据块的大小(十六进制)。作为 HTTP/1.1 兼容客户端的 curl 将为您解码,并且只应解码实际的正文内容。

有关格式的详细信息,请参阅 RFC 7230 section 4.1