from flask import Flask
from flask import request
from requests import post
from json import dumps
app = Flask(__name__)
@app.route('/post', methods=['GET', 'POST'])
def hello_world():
result = {}
result['code'] = 0
result['msg'] = 'failed'
if request.method == 'POST':
try:
post_url = ''
data = dumps(request.form)
res = post(url=post_url, data=data, timeout=20)
code = res.status_code
result['code'] = code
html = res.text
result['html'] = html
if code == 200:
result['msg'] = 'success'
except Exception as e:
result['code'] = 408
result['error_msg'] = f'{e}'
else:
result['code'] = 405
result['error_msg'] = '请使用post请求'
return dumps(result)
if __name__ == '__main__':
app.run(host='', port='8080')
网友评论