如何在Python中使用flask框架调用post接口-创新互联
这篇文章将为大家详细讲解有关如何在Python中使用flask框架调用post接口,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
在博乐等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站制作、成都外贸网站建设 网站设计制作定制网站开发,公司网站建设,企业网站建设,成都品牌网站建设,全网营销推广,外贸网站建设,博乐网站建设费用合理。具体如下:
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 调用:
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 -
关于如何在Python中使用flask框架调用post接口就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
文章题目:如何在Python中使用flask框架调用post接口-创新互联
转载来于:http://azwzsj.com/article/ghphd.html