您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何在Python中使用flask框架調(diào)用post接口,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
具體如下:
from flask import Flask,render_template,request app = Flask(__name__) @app.route("/login",methods = ['POST','GET']) def login(): if request.method == "POST": username = request.form.get('username') password = request.form.get('password') print username print password return u'POST'+'+'+username+'+'+password if request.method == "GET": print 'call get now' username = request.args.get('username') password = request.args.get('password') print username print password return username if __name__ == '__main__': app.run(host='0.0.0.0',port=6000,debug=True)
中國[root@node01 flask]# curl 'http://192.168.137.1:6000/login?username=中國&password=密碼'
中國[root@node01 flask]#
192.168.137.2 - - [13/Nov/2017 09:55:35] "GET /login?username=中國&password=密碼 HTTP/1.1" 200 -
call get now
中國
密碼
POST 調(diào)用:
use JSON; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0"); my $cookie_jar = HTTP::Cookies->new( file=>'lwp_cookies.txt', autosave=>1, ignore_discard=>1); $ua->cookie_jar($cookie_jar); my $token_url= ' http://192.168.137.1:6000/login'; my $res = $ua->post($token_url, { 'username'=>'99999@zjtlcb.com', 'password'=>'1234567' }); print $res->content(); print "\n";
[root@node01 ~]#
[root@node01 ~]# perl flask.pl
POST+99999@zjtlcb.com+1234567
from flask import Flask,render_template,request app = Flask(__name__) @app.route("/login",methods = ['POST','GET']) def login(): if request.method == "POST": username = request.form.get('username') password = request.form.get('password') print 'call post now' print username print password return u'POST'+'+'+username+'+'+password if request.method == "GET": print 'call get now' username = request.args.get('username') password = request.args.get('password') print username print password return username if __name__ == '__main__': app.run(host='0.0.0.0',port=6000,debug=True)
call post now
99999@zjtlcb.com
1234567
192.168.137.2 - - [13/Nov/2017 10:03:56] "POST /login HTTP/1.1" 200 -
關(guān)于如何在Python中使用flask框架調(diào)用post接口就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。