我正在尝试使用python requests包发送HTTP POST请求。
工作的curl命令如下所示(从chrome dev tools的网络选项卡中捕获,右键单击someFile.php,然后选择"copy as cURL")。当在终端中运行时,它输出一个有效的、非空的响应。
curl 'https://somedomain.com/someFile.php' \
--data-raw $'abc=ZXC%20*%20QWE%20***%20BNM%20((someThing%20%3D%200))%20AND%20anotherThing%20%3E%3D%20\'2020-5-9\'%20IOP%20&someparam=1&myhash=a5d96895cab824fbd9bb85627a8f909d'我尝试用python复制POST请求:
import requests
url = 'https://somedomain.com/someFile.php'
out = requests.post(url,data=r'abc=ZXC%20*%20QWE%20***%20BNM%20((someThing%20%3D%200))%20AND%20anotherThing%20%3E%3D%20\'2020-5-9\'%20IOP%20&someparam=1&myhash=a5d96895cab824fbd9bb85627a8f909d')
print(out.text)..。但这只打印一个空字符串。
如何在python中处理这个curl命令?
发布于 2021-08-21 02:47:04
只需将Content-Type报头设置为application/x-www-form-urlencoded就可以解决您的问题。
headers={}
headers["Content-Type"]="application/x-www-form-urlencoded"
data="....."
output=requests.post(url,headers=headers,data=data)发布于 2021-08-07 23:23:52
url="https://somedomain.com/someFile.php"
params = {"abc":"text without quote symbols", "someParam":.... }
res=requests.post(url, params=params)
print(res.text) https://stackoverflow.com/questions/68696683
复制相似问题