HEAD HTTP Requests in Python 2: Retrieving Headers for MIME Type Determination
Question:
To determine the MIME type of a URL without downloading the content, how can a HEAD request be sent in Python 2?
Answer:
urllib2 offers a convenient approach to execute HEAD requests. It simplifies the process by parsing the URL, eliminating the need to manually split it into host name and path:
The headers can be accessed through response.info(). Additionally, you can retrieve the redirected URL using response.geturl():
The above is the detailed content of How to Use HEAD Requests in Python 2 to Determine MIME Type Without Downloading Content?. For more information, please follow other related articles on the PHP Chinese website!