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

时间:2017-03-21 21:28:44

标签: python curl python-requests

example.py

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

上面这个例子很有用。

我想我的问题只是简单地说是上述帖子请求的等效curl命令是什么?

有点令人尴尬的问题但是我已经阅读了文档并检查了SO并且找不到答案,更不用说我使用了能够做到这一点而忘记了如何。

我正在尝试:

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

但是已经尝试了许多其他变种,所有返回都未能连接,连接被拒绝。

2 个答案:

答案 0 :(得分:1)

它相当于:

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

一些提示要找出来:

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

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from flask import Flask, request

app = Flask("HttpDump")

@app.route("/account/", methods=['POST'])
def postAirService():
    print 'Headers: '
    print request.headers
    print 'Payload: '
    print request.data

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=6789, debug=False)

然后针对它运行脚本,它将获取信息:

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 -

答案 1 :(得分:0)

试试这个:

@echo off :TIMER pause timeout 60 shutdown -l :LOGIN echo Enter password to stop the timer! set /p pass ="Password: " if NOT %pass%== Password goto :FAIL if %pass%== Password goto :Success :FAIL echo Invalid password please try again! goto :LOGIN :SUCCESS exit