Python Flask 示例(保存为 server.py 运行在 13032 端口):
from flask import Flask, request, jsonify
from flask_cors import CORS
app = Flask(__name__)
CORS(app) # 允许跨域
@app.route('/api/headers')
def headers():
return jsonify({
'headers': dict(request.headers),
'remote_addr': request.remote_addr,
'url': request.url
})
@app.route('/')
def index():
return app.send_static_file('index.html')
if __name__ == '__main__':
app.run(host='127.0.0.1', port=13032)
运行:pip install flask flask-cors && python server.py