How do you send a HEAD HTTP request in Python 2? -


what i'm trying here headers of given url can determine mime type. want able see if http://somedomain/foo/ return html document or jpeg image example. thus, need figure out how send head request can read mime type without having download content. know of easy way of doing this?

edit: answer works, nowadays should use requests library mentioned other answers below.


use httplib.

>>> import httplib >>> conn = httplib.httpconnection("www.google.com") >>> conn.request("head", "/index.html") >>> res = conn.getresponse() >>> print res.status, res.reason 200 ok >>> print res.getheaders() [('content-length', '0'), ('expires', '-1'), ('server', 'gws'), ('cache-control', 'private, max-age=0'), ('date', 'sat, 20 sep 2008 06:43:36 gmt'), ('content-type', 'text/html; charset=iso-8859-1')] 

there's getheader(name) specific header.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -