解决python使用urllib2不能随意修改HTTP method办法
2014-06-24 18:26
501 查看
原理:重载urllib2使用的Request类。
import urllib2
#urllib2 默认不能自由设置HTTP的method。如果需要自由定制method。可以使用该类。
#req = setMethodRequest(url,"GET")
class RequestMethod(urllib2.Request,object):
def __init__(self, url, method=None,data=None, headers={},
origin_req_host=None, unverifiable=False):
self.method = method
super(RequestMethod,self).__init__(url, data=data,headers=headers,origin_req_host=origin_req_host,unverifiable=unverifiable)
def get_method(self):
if self.method != None:
return self.method
else:
return super(RequestMethod,self).get_method()
def set_method(self,method):
self.method = method
def setMethodRequest(url,method):
return RequestMethod(url,method=method)
import urllib2
#urllib2 默认不能自由设置HTTP的method。如果需要自由定制method。可以使用该类。
#req = setMethodRequest(url,"GET")
class RequestMethod(urllib2.Request,object):
def __init__(self, url, method=None,data=None, headers={},
origin_req_host=None, unverifiable=False):
self.method = method
super(RequestMethod,self).__init__(url, data=data,headers=headers,origin_req_host=origin_req_host,unverifiable=unverifiable)
def get_method(self):
if self.method != None:
return self.method
else:
return super(RequestMethod,self).get_method()
def set_method(self,method):
self.method = method
def setMethodRequest(url,method):
return RequestMethod(url,method=method)
相关文章推荐
- iOS 9 iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- 由于使用 xfire/HttpMethod 造成Socket连接池满的问题及解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9与XCode7中不能使用http连接的解决办法
- iOS9 HTTP 不能正常使用的解决办法(详细plist设置)
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS疯狂详解之iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- iOS9 HTTP 不能正常使用的解决办法
- IOS9 HTTP 不能正常使用的解决办法