Python 为什么来自服务器的cURL响应是HTTP/1.0?

Python 为什么来自服务器的cURL响应是HTTP/1.0?,python,http,curl,Python,Http,Curl,我已经在终端中创建了简单的服务器 python -m SimpleHTTPServer 8000 当我发送命令curl-I时http://localhost:8000 * Rebuilt URL to: http://localhost:8000/ * Trying ::1... * connect to ::1 port 8000 failed: Connection refused * Trying 127.0.0.1... * Connected to localhost (12

我已经在终端中创建了简单的服务器

python -m SimpleHTTPServer 8000
当我发送命令
curl-I时http://localhost:8000

* Rebuilt URL to: http://localhost:8000/
*   Trying ::1...
* connect to ::1 port 8000 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.43.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/2.7.12
< Date: Sun, 07 Aug 2016 10:02:23 GMT
< Content-type: text/html; charset=utf-8
< Content-Length: 9747
<
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
...
</html>
* Closing connection 0
命令结果是一个请求:

127.0.0.1---[07/Aug/2016 14:53:22]“GET/HTTP/1.1”200-

但回应是HTTP/1.0

HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/2.7.12
Date: Sun, 07 Aug 2016 10:02:08 GMT
Content-type: text/html; charset=utf-8
Content-Length: 9747
curl-vhttp://localhost:8000

* Rebuilt URL to: http://localhost:8000/
*   Trying ::1...
* connect to ::1 port 8000 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.43.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/2.7.12
< Date: Sun, 07 Aug 2016 10:02:23 GMT
< Content-type: text/html; charset=utf-8
< Content-Length: 9747
<
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
...
</html>
* Closing connection 0
*重建的URL到:http://localhost:8000/
*正在尝试::1。。。
*连接到::1端口8000失败:连接被拒绝
*正在尝试127.0.0.1。。。
*已连接到本地主机(127.0.0.1)端口8000(#0)
>GET/HTTP/1.1
>主机:localhost:8000
>用户代理:curl/7.43.0
>接受:*/*
>
*HTTP 1.0,假设在正文之后关闭

我们如何解释这一点?为什么服务器响应不是HTTP/1.1

它只是一个版本号,服务器支持旧的1.0协议


请参见

curl
默认使用7.33.0版的HTTP/1.1(您的版本是7.43.0)。在
男子卷发中

--http1.1
              (HTTP) Tells curl to use HTTP version 1.1. This is the internal default version. (Added in 7.33.0)
因此
curl
将使用
HTTP/1.1
向您的服务器发出请求

这条线

127.0.0.1---[07/Aug/2016 14:53:22]“GET/HTTP/1.1”200-

只是一个日志条目,它告诉您有一个请求是用expected get
HTTP/1.1
发出的,但这并不意味着服务器必须用
HTTP/1.1
响应,有关详细信息,请参阅Karoly Horvath的链接

查看
SimpleHTTPServer
的源代码,您可以看到有一个
HTTP/0.9

默认请求版本
变量随后被分配到第244行中的
self.request版本


执行响应的函数是
send\u response
,第402行与
HTTP/0.9
进行了比较,这导致协议版本是
protocol\u version
is
HTTP/1.0
in

我以前在Python中没有使用过类似的东西,所以我可能完全不懂,但通过谷歌搜索,我发现了一些可能的解释:“这指定了响应中使用的HTTP协议版本。”在启动之前,您可以为
SimpleHTTPServer
设置一个
protocol\u版本
属性。谢谢您,Karoly!谢谢你,聪女!事实上,curl使用HTTP/1.1的时间要长得多,基本上是永远。