【发布时间】:2022-12-06 15:27:01
【问题描述】:
标签: api
标签: api
以下是我在您的代码中发现的一些常见错误:
post,而在您的代码中,您使用的是 requests.get()。你应该使用requests.post()
示例发布请求:
import requests
import json
# your API url
url = "https://your-api-link/endpoint"
# your API headers
headers = {"Content-Type": "application/json; charset=utf-8"}
# It should be as mentioned in the documentation.
data = {
"id": 1001,
"name": "myAPI",
"passion": "givingResponse",
}
# making API request
response = requests.post(url, headers=headers, json=data)
print("Status Code", response.status_code)
print("JSON Response ", response.json())
【讨论】: