普通post请求

>>> import requests
>>> url = 'http://httpbin.org/post'
>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post(url, data=payload)
>>> print(r.text)
{
  ...
  "form": {
    "key2": "value2",
    "key1": "value1"
  },
  ...
}

若POST的数据是字典将其用双引号转成字符串

>>> payload = {'data': "{'a':{'b':'c','d':'e'},'f':[{'g':'h','i':'j'}]}"}
>>> r = requests.post(url, data=payload)
>>> r.text
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "data": "{'a':{'b':'c','d':'e'},'f':[{'g':'h','i':'j'}]}"
  },
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Connection": "close",
    "Content-Length": "126",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.18.4"
  },
  "json": null,
  "origin": "113.201.61.106",
  "url": "http://httpbin.org/post"
}

在server端(django1.5.1)以下使用以下代码可获取数据

req_data = self.request.get('data', "")
logging.info("Src json string: %s" % str(req_data))
req_obj = simplejson.loads(req_data)

参考链接: post