JSON API 请求
输入
curl https://api.example.com/users --json '{"name":"Ada"}'输出
requests.request("POST", url, headers=headers, json=json_data, timeout=30)有效 JSON 会生成 Python 字典,而不是未经处理的字符串。
AppHelp
粘贴 cURL 即时获得易读 Python,并检查请求详情、敏感值警告、示例、复制与 .py 下载。
粘贴命令后立即检查 Python requests 代码。
import requests
headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}
json_data = {
"name": "Ada",
"active": True
}
response = requests.request(
"POST",
"https://api.example.com/users",
headers=headers,
json=json_data,
timeout=30,
allow_redirects=False,
)
response.raise_for_status()
print(response.text)粘贴 cURL 命令即可实时生成 Python requests 代码。工具可识别方法、请求头、JSON 与表单正文、Basic 认证、Cookie、多部分文件、重定向、超时和关闭 TLS 验证的参数,并且不会把命令发送到服务器。
curl https://api.example.com/users --json '{"name":"Ada"}'requests.request("POST", url, headers=headers, json=json_data, timeout=30)有效 JSON 会生成 Python 字典,而不是未经处理的字符串。
curl https://api.example.com/profile -H 'Authorization: Bearer TOKEN'
headers = {"Authorization": "Bearer TOKEN"}分享代码前请打开密钥遮蔽。
curl https://api.example.com/avatar -F 'avatar=@photo.png'
files = {"avatar": open("photo.png", "rb")}运行脚本前确认本地文件存在。