简体   繁体   中英

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

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?

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.

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:

#!/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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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