如何通过POST从服务器获取响应JSON词典:
import json
import requests
url = 'http://apiurl.com'
parameters = {'code':1,
'user': 'username',
'password': 'password'
}
headers = {'content-type': 'application/json'}
response = requests.post(url, data = json.dumps(parameters),headers=headers)
print(response)
输出:响应[200]
答案 0 :(得分:2)
response = requests.post(url, data=json.dumps(parameters), headers=headers)
print(response)
print(response.text)
答案 1 :(得分:1)
因为,您将收到一个JSON对象,您只需使用request's built-in JSON decoder,只需这样做:
j = response.json()