我正在尝试从头开始通过 Flask 构建一个 cors 代理。这是我的代码
@app.route('/api/v1/cors/url=<name>&method=<method>', methods=['GET'])
def api_cors(name, method):
if method == 'http' or method == 'https':
r = request.urlopen(method+"://"+name)
return r.read()
else:
return "method not set!"
到目前为止它运行良好,但我有一个问题,当我传递“url=google.com&method=https”时它工作正常但是当我传递类似“url=google.com/images/image.jpg&method=”的内容时https""/"将被视为一个新目录
有没有办法在 flask 中规避这个问题?
请您参考如下方法:
不要尝试将值作为路由本身的一部分传递。将其作为查询参数传递。
@app.route('/api/v1/cors/')
def api_cors():
url = request.args.get('url')
并将其命名为 "/api/v1/cors/?url=https://google.com/images/image.jpg"。
