Get request and response headers
There are two main parts to HTTP requests – a header and a body. Headers are information lines that contain specific metadata about the response and tell the client how to interpret the response. With this module, we can test whether the headers can provide web server information.
HTTP headers contain different information about the HTTP request and the client that you are using for doing the request. For example, User-Agent
provides information about the browser and operating system you are using to perform the request.
The following script will obtain the site headers through the response object’s headers. For this task, we can use the headers
property or the getheaders()
method. The getheaders()
method returns the headers as a list of tuples in the format (header name, header value)
. You can find the following code in the get_headers_response_request.py
file inside the urllib.request
folder:
import urllib.request
from urllib...