Possible Duplicate:
How do you send a HEAD HTTP request in Python?
I am using Python's urllib and urllib2 to do an automated login. I am also using HTTPCookieProcessor to automate the handling of the cookies. The code is somewhat like this:
o = urllib2.build_opener( urllib2.HTTPCookieProcessor() )
# assuming the site expects 'user' and 'pass' as query params
p = urllib.urlencode( { 'username': 'me', 'password': 'mypass' } )
# perform login with params
f = o.open( 'http://www.mysite.com/login/', p )
data = f.read()
f.close()
# second request
t = o.open( 'http://www.mysite.com/protected/area/' )
data = t.read()
t.close()
Now, the point is that I don't want to waste bandwidth in downloading the contents of http://www.mysite.com/login/, since all I want to do is receive the cookies (which are there in the Headers). Also, the site redirects me to http://www.mysite.com/userprofile when I first login (that is, the f.geturl() = http://www.mysite.com/userprofile).
So is there any way that I can avoid fetching the content in the first request?
P.S. Please don't ask me why am I avoiding the small network usage of transferring the content. Although the content is small, I still don't want to download it.