
上QQ阅读APP看书,第一时间看更新
Checking HTTP headers
The response.headers statement provides the headers of the web server response. Basically, the response is an object dictionary, and with the items() method, we can iterate with the key-value format for access to the header's response.
You can find the following code in the get_headers.py file:
#!/usr/bin/env python3
import requests
response = requests.get('http://github.com')
try:
for key,value in response.headers.items():
print('%s: %s' % (key, value))
except Exception as error:
print('%s' % (error))
In this screenshot, we can see the script execution for the github.com domain:

We can also find browser add-ons or plugins that can help us in collecting information on the headers that are sent in the requests.
Among the available plugins for Firefox, we can suggest the HTTP Header Live add-ons:

With this plugin, we can get the headers for the request and response for a specific domain URL:
