The following simple python script prints the HTTP response header for the URL passed as a command line parameter:
Output of the above script, with http://python.org as the command line parameter, is shown below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import sys | |
def print_http_respose_header(url): | |
try: | |
response = urllib2.urlopen(url) | |
for key, value in response.info().items(): | |
print key + ' => ' + value | |
except: | |
print 'error message' | |
def main(): | |
print_http_respose_header(sys.argv[1]) | |
if __name__ == '__main__': | |
main() |
Output of the above script, with http://python.org as the command line parameter, is shown below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
content-length => 45495 | |
via => 1.1 varnish | |
x-cache => HIT | |
accept-ranges => bytes | |
strict-transport-security => max-age=63072000; includeSubDomains | |
vary => Cookie | |
server => nginx | |
connection => close | |
x-served-by => cache-sv95-SJC3 | |
x-cache-hits => 19 | |
date => Wed, 18 Jun 2014 16:56:04 GMT | |
x-frame-options => SAMEORIGIN | |
content-type => text/html; charset=utf-8 | |
age => 863 |