这个python请求POST请求的等效curl命令是什么?

2024-06-25 22:48:54 发布

您现在位置:Python中文网/ 问答频道 /正文

在示例.py在

url="http://authserver:5000/account"
params ={'username': username,'email': email, 'password': password}
data = requests.post(url=url, params=params)

上面这个例子很管用。在

我想我的问题很简单,上面的post请求对应的curl命令是什么?在

这是一个令人尴尬的问题,但我已经阅读了文档并进行了检查,却找不到答案,更不用说我以前能做到这一点,却忘了怎么做。在

我正在尝试:

^{pr2}$

但尝试过许多其他变体,都以连接失败,连接拒绝。在


Tags: pyhttpurl示例dataemailusernameaccount
2条回答

相当于:

curl -X POST 'http://authserver:5000/account/?username=test&password=password&email=me@email.com'

一些提示可以找到答案:

编写一个简单的脚本来转储http请求的详细信息:

^{pr2}$

然后对其运行脚本,它将获得以下信息:

Headers:
Content-Length: 0
User-Agent: python-requests/2.11.1
Connection: keep-alive
Host: localhost:6789
Accept: */*
Content-Type:
Accept-Encoding: gzip, deflate


Payload:

127.0.0.1 - - [22/Mar/2017 05:45:49] "POST /account/?username=test&password=passwd&email=me%40email.com HTTP/1.1" 200 -

试试这个:

curl -d "user=test&email=test&password=test" http://authserver:5000/account

相关问题 更多 >