简体   繁体   中英

Print response JSON from server with HTTP POST

How can I get respon JSON dictionaries from server with POST:

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)

output: Response [200]

response = requests.post(url, data=json.dumps(parameters), headers=headers)
print(response)
print(response.text)

因为,您将收到一个JSON对象,您只需使用请求的内置JSON解码器,只需执行以下操作:

j = response.json()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM