http post by requests
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了http post by requests相关的知识,希望对你有一定的参考价值。
普通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
以上是关于http post by requests的主要内容,如果未能解决你的问题,请参考以下文章
Flutter 报错 DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform(代码片段
axios.post请求出错:Request header field content-type is not allowed by Access-Control-Allow-Headers in……
在这个 spark 代码片段中 ordering.by 是啥意思?
angularjs post Request header field Content-Type is not allowed by Access-Control-Allow-Headers in p