Python flaskフレームpostインタフェース呼び出し例
3029 ワード
この例では、Python flaskフレームワークpostインタフェース呼び出しについて説明します.皆さんの参考にしてください.具体的には以下の通りです.
中国[root@node01 flask]# curl 'http://192.168.137.1:6000/login?username=中国&password=パスワード'中国[root@node01flask]#192.168.137.2--[13/Nov/2017 09:55:35]「GET/login?username=中国&password=パスワードHTTP/1.1」200-call get now中国パスワード
POSTコール:
[root@node01 ~]# [root@node01 ~]# perl flask.pl [email protected]+1234567
call post now [email protected] 1234567 192.168.137.2 - - [13/Nov/2017 10:03:56] "POST/login HTTP/1.1"200 -
flaskフレームワークに基づくPythonプログラムの設計に役立つことを期待します.
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@node01flask]#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'=>'[email protected]',
'password'=>'1234567'
});
print $res->content();
print "
";
[root@node01 ~]# [root@node01 ~]# perl flask.pl [email protected]+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 [email protected] 1234567 192.168.137.2 - - [13/Nov/2017 10:03:56] "POST/login HTTP/1.1"200 -
flaskフレームワークに基づくPythonプログラムの設計に役立つことを期待します.