配置谷歌应用程序引擎的应用程序跨域 [英] Configure google app engine application for cross-domain
问题描述
请您指教,我们如何配置我们托管在谷歌应用程序引擎的Python应用程序接受的选项,GET,POST,PUT和DELETE AJAX从浏览器正在做?
Could you please advise, how we can configure our Python app hosted on Google App Engine to accept the OPTIONS, GET, POST, PUT and DELETE from AJAX being done from browser?
此类电话的具体细节XmlHTT prequest第一确实OPTIONS请求到服务器以查看什么允许跨域动词和如果希望的一个是在列表 - 浏览器执行此请求之后
The specifics of such calls are XmlHTTPRequest first does OPTIONS request to the server to see what cross-domain verbs are allowed and if desired one is in the list - browser does this request afterwards.
目前,我们只是得到一个405不允许的方法在尝试浏览器做OPTIONS请求。
Right now we just get a 405 Method Not Allowed in attempt of browser to do OPTIONS request.
AJAX调用正在从另一个站点/域完成的。
AJAX calls are being done from another site/domain.
感谢您,
罗马。
推荐答案
要绕过同源政策允许浏览器跨域请求是采用 JSONP 但AFAIK,它只支持 GET
动词;事实上,这是一个GET请求来检索的src
的<脚本>
标记注入到DOM文档
One way to bypass the same-origin policy allowing browsers cross-domain requests is adopting JSONP but AFAIK, it only supports the GET
verb; In fact, it's a GET request to retrieve the src
of a <script>
tag injected in the DOM Document
如果JSONP是不是一种选择,一个更现代的方法是使用 CORS ,加在访问控制 - 允许 - 原产地 HTTP来响应头 * :
If JSONP is not an option, a more modern way is by using CORS, adding the Access-Control-Allow-Origin Http header to the response *:
在的Python 的:
self.response.headers['Access-Control-Allow-Origin'] = '*'
在的Java 的:
resp.setHeader("Access-Control-Allow-Origin", "*");
这篇关于配置谷歌应用程序引擎的应用程序跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!