本文整理汇总了Python中urllib2.Request.get_header方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_header方法的具体用法?Python Request.get_header怎么用?Python Request.get_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.get_header方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_cookie
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_header [as 别名]
def get_cookie(self, path):
request = Request(path)
if len(self._cookies) == 0:
self.load()
self.add_cookie_header(request)
if request.get_header('Cookie'):
return "Cookie: %s\r\n" % request.get_header('Cookie')
return None
示例2: test_proxy_https_proxy_authorization
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_header [as 别名]
def test_proxy_https_proxy_authorization(self):
o = OpenerDirector()
ph = urllib2.ProxyHandler(dict(https="proxy.example.com:3128"))
o.add_handler(ph)
https_handler = MockHTTPSHandler()
o.add_handler(https_handler)
req = Request("https://www.example.com/")
req.add_header("Proxy-Authorization", "FooBar")
req.add_header("User-Agent", "Grail")
self.assertEqual(req.get_host(), "www.example.com")
self.assertIsNone(req._tunnel_host)
r = o.open(req)
# Verify Proxy-Authorization gets tunneled to request.
# httpsconn req_headers do not have the Proxy-Authorization header but
# the req will have.
self.assertNotIn(("Proxy-Authorization", "FooBar"), https_handler.httpconn.req_headers)
self.assertIn(("User-Agent", "Grail"), https_handler.httpconn.req_headers)
self.assertIsNotNone(req._tunnel_host)
self.assertEqual(req.get_host(), "proxy.example.com:3128")
self.assertEqual(req.get_header("Proxy-authorization"), "FooBar")
示例3: get_header
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_header [as 别名]
def get_header(self, name, default = None):
if not isinstance(self.headers, HeaderDictionary):
return _Request.get_header(self, name, default)
return self.headers.get_header_value(name, default)