我正在尝试使用 python 发出 post 请求,但它不起作用
import requests
payload = { 'accountID':'20176429'}
h = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post("https://www.simplicialsoftware.com/api/account/GetPlayerProfile", data=payload, headers=h)
print(r.status_code, r.reason)
print(r.headers)
print(r.text[:300] + '...')
输出:
404 Not Found
{'Server': 'nginx/1.20.0', 'Date': 'Sun, 03 Oct 2021 14:00:44 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Expires': '-1', 'Strict-Transport-Security': 'max-age=2592000'}
...
当我对 Insomnia 提出同样的要求时:
如果我从 Insomnia 中删除 Content-Type 标头,我会收到 404 错误:
我正在从终端运行程序,使用 python3 版本 3.6.9 和命令:
python3 request.py
当我使用端点:https://www.simplicialsoftware.com/时,我得到:
200 OK
{'Server': 'nginx/1.20.0', 'Date': 'Sun, 03 Oct 2021 14:44:25 GMT', 'Content-Type': 'text/html', 'Content-Length': '15359', 'Connection': 'keep-alive', 'Last-Modified': 'Thu, 30 Sep 2021 04:23:26 GMT'}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Nebulous</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="keywords" content="nebulous, simplicial, orborous, rebellious, simplicial software">
<meta name="author" content="Andre Luiz Lourenco"/>
怎么了?一些帮助?