Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取HTTP服务器的服务器头_Python_Http - Fatal编程技术网

Python 获取HTTP服务器的服务器头

Python 获取HTTP服务器的服务器头,python,http,Python,Http,我想用Python获取HTTP的服务器头。我不知道如何获取它,我查看了超文本传输协议的RFC,进入了服务器部分 The Server response-header field contains information about the software used by the origin server to handle the request. The field can contain multiple product tokens (section 3.8) and c

我想用Python获取HTTP的
服务器
头。我不知道如何获取它,我查看了
超文本传输协议的
RFC
,进入了
服务器
部分

 The Server response-header field contains information about the
   software used by the origin server to handle the request. The field
   can contain multiple product tokens (section 3.8) and comments
   identifying the server and any significant subproducts. The product
   tokens are listed in order of their significance for identifying the
   application.

我们怎样才能得到它?我可以猜测,使用
操作系统
平台
,等等。

我假设您想要:

  • 向web服务器发送HTTP请求并检索“服务器”标头 从HTTP响应
  • 您想使用python
“requests”是一个非常流行的用于生成HTTP请求的库()

下面是一个代码示例,非常有可能指导您实现所需的功能

import requests
response = requests.get("http://example.com")
print(response.headers['Server'])

您如何发出HTTP请求?@klauds。我构建了自己的http服务器,我想在响应标题中包含
server
标题,这与您的问题正好相反。为什么是fam?您的问题是如何获取作为客户端任务的服务器头,您的评论是如何设置作为服务器任务的服务器头。