网络编程 -- flask

demo.py

1
2
3
4
5
6
7
8
9
10
11
12
from flask import Flask, request, jsonify, Respons

app = Flask(__name__)

@app.route('/hi', methods=['GET', 'POST'])
def hello_world():
logger.info('---hi Qiansi Tech SR')
return 'Qiansi Tech SR'

if __name__ == '__main__':
# Rel Server [gunnicor run in 9020]
app.run(port=9021) # test in 9021

client

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def request_demo(test_on_server=False):
try:
# url = 'http://127.0.0.1:{}/cycle/hi'.format(args.port)
# url = 'http://cartoon.fuyuncc.com/cycle/hi'.format(args.port)
url = 'http://cartoon.fuyuncc.com/srserver/hi'
if test_on_server:
url = 'http://127.0.0.1:9021/hi'
print('-url', url)

r = requests.get(url)
print(r)
print(r.text)
except Exception as e:
print(e)