我正试图通过django 中的POST请求发送数据
url = 'http://db-003:8013/v1/upgrade-ce'
payload = {
"cluster_name": cluster_name,
"cec_id": cec_id,
"new_version": new_version,
"cr_number": cr_number,
}
response = requests.post(url, data=payload)
接收端接线柱方法:
cluster name = request.data.get('cluster_name')
接收器端的数据
<QueryDict: {'cluster_name': ['abcd'], 'cec_id': ['abc'], 'new_version': ['8.0.23'], 'cr_number': ['6587657']}>
所获得的数据是一个列表,而不是单个字符串。已尝试json.dumps()
,但在接收器端,数据为空。
如何获得单个字符串
在headers和json.dumps(有效负载(中以application/json的形式发送内容类型应该可以工作。
url = 'http://db-003:8013/v1/upgrade-ce'
payload = {
"cluster_name": cluster_name,
"cec_id": cec_id,
"new_version": new_version,
"cr_number": cr_number,
}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, data=json.dumps(payload), headers=headers)