如何从我的烧瓶应用程序向另一个站点发送GET请求? [英] How can I send a GET request from my flask app to another site?
问题描述
最初,我尝试将客户端的ajax请求发布到第三方url,但似乎浏览器与此相关的安全问题.我考虑过将ajax发送到服务器端,从那里向第三方发送GET请求,获取响应并将其发送回客户端.我如何用长颈瓶做到这一点?
Originally, I tried to post an ajax request from my client side to a third party url, but it seems that the browser have security issues with that. I thought about sending an ajax to the server side, from there to send a GET request to the third party, get the response and send it back to the client side. How can I do that with flask?
推荐答案
安装requests
模块(比使用urllib2
更好),然后定义一个发出必要请求的路由-类似于:
Install the requests
module (much nicer than using urllib2
) and then define a route which makes the necessary request - something like:
import requests
from flask import Flask
app = Flask(__name__)
@app.route('/some-url')
def get_data():
return requests.get('http://example.com').content
不过,根据您的设置,最好将您的网络服务器配置为在特定URL下将代理反向代理到目标站点.
Depending on your set up though, it'd be better to configure your webserver to reverse proxy to the target site under a certain URL.
这篇关于如何从我的烧瓶应用程序向另一个站点发送GET请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!