检查请求头中的Content-Type字段是否正确设置。如果请求体中没有媒体文件,则应将Content-Type设置为"application/json"或"text/plain"。以下是一个示例代码:
import requests
url = "http://example.com/api"
headers = {
"Content-Type": "application/json" # or "text/plain"
}
payload = {
"key": "value"
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
# handle the response
else:
# handle the error
上一篇:API请求返回403禁止访问。
下一篇:API请求返回cors