gpt4 book ai didi

Python flask框架post接口调用示例

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 32 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Python flask框架post接口调用示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例讲述了Python flask框架post接口调用。分享给大家供大家参考,具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 调用

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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程序设计有所帮助.

原文链接:https://blog.csdn.net/zhaoyangjian724/article/details/78517437 。

最后此篇关于Python flask框架post接口调用示例的文章就讲到这里了,如果你想了解更多关于Python flask框架post接口调用示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com