简体   繁体   English

使用HTTP POST从服务器打印响应JSON

[英]Print response JSON from server with HTTP POST

How can I get respon JSON dictionaries from server with POST: 如何通过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)

output: Response [200] 输出:回复[200]

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

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

j = response.json()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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