Python flask框架post接口调用示例
作者:xujiang 时间:2021-01-24 17:06:47
本文实例讲述了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@xxxxx.com',
'password'=>'1234567'
});
print $res->content();
print "\n";
[root@node01 ~]#
[root@node01 ~]# perl flask.pl
POST+99999@xxxxx.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@xxxxx.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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
抛砖引玉Web2.0设计指南
2008-06-30 12:49:00
![](https://img.aspxhome.com/file/UploadPic/up/2008063013584749.gif)
Django使用channels + websocket打造在线聊天室
2022-01-05 11:16:26
![](https://img.aspxhome.com/file/2023/9/76729_0s.gif)
Python文本特征抽取与向量化算法学习
2023-07-19 09:44:29
![](https://img.aspxhome.com/file/2023/1/81501_0s.jpg)
使用Javascript实现选择下拉菜单互移并排序
2023-09-07 18:14:45
![](https://img.aspxhome.com/file/2023/2/56302_0s.png)
php中防止SQL注入的最佳解决方法
2023-08-19 21:52:20
SQL的小常识, 备忘之用, 慢慢补充.
2011-11-03 17:19:45
Python简单获取网卡名称及其IP地址的方法【基于psutil模块】
2022-10-07 19:52:15
提升设计品质的8个布局方案[译]
2010-03-18 16:06:00
![](https://img.aspxhome.com/file/UploadPic/20103/18/01-33s.jpg)
Python爬虫爬取煎蛋网图片代码实例
2023-08-17 07:10:38
![](https://img.aspxhome.com/file/2023/6/85056_0s.png)
Python实现微博动态图片爬取详解
2023-09-14 05:47:25
![](https://img.aspxhome.com/file/2023/0/61730_0s.jpg)
js字符串日期yyyy-MM-dd转化为date示例代码
2023-08-06 16:35:58
Python自动化测试PO模型封装过程详解
2023-08-23 18:59:49
![](https://img.aspxhome.com/file/2023/0/84040_0s.png)
python torch.utils.data.DataLoader使用方法
2023-02-20 16:00:16
![](https://img.aspxhome.com/file/2023/9/85079_0s.png)
一种有创意的CSS命名规则
2008-06-15 15:18:00
表格艺术经典回顾
2013-07-14 11:11:04
关于使用python反编译apk签名出包的问题
2022-12-19 19:39:04
PHP析构函数destruct与垃圾回收机制的讲解
2023-07-11 21:05:36
巧用Dreamweaver4文件库更新网站
2007-02-03 11:31:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113133681s.gif)
python可视化大屏库big_screen示例详解
2021-10-16 14:32:39
![](https://img.aspxhome.com/file/2023/7/87487_0s.jpg)
斜角滑动门导航条 DIV+CSS
2008-07-19 15:45:00
![](https://img.aspxhome.com/file/UploadPic/20087/19/200871916554645s.gif)