I would like to send a http request with METHOD=HEAD using python 2. In mechanize there is a nice function called mechanize.Request. Unfortunately i only can set METHOD to either GET or POST but nothing else. Do you know whether there is a way to do that?
Asked
Active
Viewed 307 times
1 Answers
0
Use this:
import urllib2
class RequestWithMethod(urllib2.Request):
def __init__(self, method, *args, **kwargs):
self._method = method
urllib2.Request.__init__(*args, **kwargs)
def get_method(self):
return self._method
Then do something like this:
request = RequestWithMethod("HEAD", "%s" % url)

Raj
- 3,791
- 5
- 43
- 56