http_service.py
from flask import Flask
from flask import request
import json
app = Flask(__name__)
@app.route('/abc/TEST_transmit', methods=['POST'])
def func():
if request.method == 'POST':
request_str = json.loads(request.data.decode('UTF-8'))
print(request_str)
return ('earth')
else:
print("hello earth!")
return ('sea')
命令行运行
export FLASK_APP=http_service
flask run --debugger --host=0.0.0.0 &
post_test.py
import requests
import json
def post_func(name,age):
url = 'http://192.168.78.140:5000/abc/TEST_transmit'
my_arg = {'name': name, "age":age}
print('my_arg:',my_arg)
str_json = json.dumps(my_arg)
x = requests.post(url,data = str_json)
print(x.text)
post_func('xiaoming',17)
运行: