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")}執行前確認本機檔案存在。