Normal POST request
>>> 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" }, ...}
If the data for the post is a dictionary, turn it into a string with double quotes
>>> 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"}
Use the following code to obtain data from the server side (django1.5.1)
req_data = self.request.get(‘data‘, "")logging.info("Src json string: %s" % str(req_data))req_obj = simplejson.loads(req_data)
Reference Links:
Post
HTTP POST by requests