相思资源网 Design By www.200059.com

本文实例讲述了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"GET /login" 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 -

希望本文所述对大家基于flask框架的Python程序设计有所帮助。

标签:
Python,flask,post接口

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“Python flask框架post接口调用示例”

暂无Python flask框架post接口调用示例的评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。