0

最小示例:

# -*- 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

未设置标题。

4

1 回答 1

1

You are already using the httpbin.org service, it returns you a JSON structure that includes all headers it received:

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)

When I run the above code, I get:

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
于 2012-09-20T12:17:48.617 回答