繁体   English   中英

标头设置不正确

[英]Headers are not set correctly

最小示例:

# -*- coding: utf-8 -*-
import requests

xml = """<?xml version='1.0' encoding='utf-8'?>
<a>б</a>"""

print requests.post('http://httpbin.org/post', data=xml, headers={'Authorization': 'a', 'developerToken': 'b', 'clientCostumerID': 'c'}).headers

标头未设置。

您已经在使用httpbin.org服务,它将返回一个JSON结构,其中包括它收到的所有标头:

import requests

xml = """<?xml version='1.0' encoding='utf-8'?>
<a>б</a>"""

data = requests.post('http://httpbin.org/post', data=xml, headers={'Authorization': 'a', 'developerToken': 'b', 'clientCostumerID': 'c'}).json

for headername, headervalue in data['headers'].iteritems():
    print '%s: %s' % (headername, headervalue)

当我运行上面的代码时,我得到:

Content-Length: 48
Developertoken: b
Accept-Encoding: identity, deflate, compress, gzip
Connection: keep-alive
Clientcostumerid: c
Accept: */*
User-Agent: python-requests/0.14.0 CPython/2.7.3 Darwin/11.4.0
Host: httpbin.org
Content-Type: 
Authorization: a

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM