我在我的烧瓶服务器中使用重定向来调用另一个webservice api.eg
@app.route('/hello')
def hello():
return redirect("http://google.com")
Run Code Online (Sandbox Code Playgroud)
该网址逻辑上更改为google.com,但有什么方法可以保持相同的网址?或任何其他方式来获得webservice调用.
Dan*_*iel 16
您需要向服务器"请求"数据,然后发送它.
你可以使用python stdlib函数(urllib等),但它很笨拙,所以很多人都使用'requests'库.(pip install requests)
http://docs.python-requests.org/en/latest/
所以你最终得到类似的东西
@app.route('/hello')
def hello():
r = requests.get('http://www.google.com')
return r.text
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.