简体   繁体   English

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

[英]What is the equivalent curl command for this python requests POST request?

example.py example.py

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

this example above works. 上面的这个例子有效。

I guess my question simply put is what is the equivalent curl command for the above post request? 我想我的问题就是,以上发布请求的等效curl命令是什么?

Kind of an embarrassing question but I have read the docs and checked SO and cannot find an answer, not to mention that I USED to be able to do this and just forgot how. 有点令人尴尬的问题,但是我已经阅读了文档并检查了SO,但找不到答案,更不用说我曾经能够做到这一点而忘记了如何做。

I am currently trying: 我目前正在尝试:

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

But have tried many other variations and all return with failed to connect, connection refused. 但是尝试了许多其他变体,并且所有连接均失败,连接被拒绝。

It's equivalent to: 等效于:

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

Some hint to find it out: 一些提示可以找到答案:

Write a simple script to dump http request details: 编写一个简单的脚本来转储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)

And then run your script against it, it will get info: 然后针对它运行您的脚本,它将获得以下信息:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM