我无法通过 Content-Type header 并且在 POST python 请求中内容始终为 0

I can't pass the Content-Type header and the content is always 0 on POST python request

我正在尝试使用 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 header,我会收到 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"/>

怎么了?有帮助吗?

我运行你编码并得到有效回复:

200 OK
{'Server': 'nginx/1.20.0', 'Date': 'Sun, 03 Oct 2021 14:20:56 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive'}
{"profile":"É Fda isso \uD83C\uDF42\n\n\n  ت ؛Thnnmate 座","customSkinID":0,"setNamePrice":1000,"banned":false,"chatBanned":false,"arenaBanned":false,"relationship":"NONE","profileColors":[255],"profileFonts":[],"profileFont":0,"hasCommunitySkins":false,"hasCommunityPets":false,"hasCommunityParticles...

检查您可能已在电脑中配置的阻止或重定向邮件的任何网络设置