我有一个API,它向我展示了一个使用的示例
curl -X POST -d "@-" -H "Content-Type: application/json" https://localhost.com/api/ <<EOF
{
"origin_id": "test_user_id"
}
EOF
我不知道如何在python中做到这一点。
根据man curl
:
If you start the data with the letter @, the rest should be a
file name to read the data from, or - if you want curl to read
the data from stdin.
CCD_ 2是一种bash方式;将EOF
之后的所有内容发送到"中的标准";。所以写这篇文章的另一种方式是:
curl -X POST -d '{"origin_id": "test_user_id"}' -H "Content-Type: application/json" https://localhost.com/api/
所以在python中,这将是:
import requests
requests.post('https://localhost.com/api/', data={"origin_id": "test_user_id"})