早些时候我用过httplib
模块在请求中添加标头。现在我正在尝试同样的事情requests
module.
这是我正在使用的 python 请求模块:http://pypi.python.org/pypi/requests
如何添加标题request.post()
and request.get()
。说我必须添加foobar
在标头中键入每个请求。
From http://docs.python-requests.org/en/latest/user/quickstart/
url = 'https://api.github.com/some/endpoint'
payload = {'some': 'data'}
headers = {'content-type': 'application/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
您只需要使用标头创建一个字典(键:值对,其中键是标头的名称,值是该对的值),然后将该字典传递给 headers 参数.get
or .post
method.
所以更具体地回答你的问题:
headers = {'foobar': 'raboof'}
requests.get('http://himom.com', headers=headers)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)