来自网络浏览器的跨域调用
我想从网站执行跨域 http 请求。我有什么选择?
Javascript 已经过时了,因为大多数浏览器不允许跨域调用。通常,解决方案是使用代理,但这不是此项目的选择。
我考虑的其他事情是使用 Flash 或 Java。还有其他我可以使用的平台吗?
I would like to execute a cross domain http request from a website. What are my options?
Javascript is out, because most browser don't allow cross domain calls. Generally the solution is to use a proxy, but that isn't an option for this project.
The other things I was thinking about would be to use Flash or maybe Java. Are there any other platforms that I could use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“Javascript 已经过时了,因为大多数浏览器不允许跨域调用。”
不幸的是,Javascript 肯定会出现。您只需使用您喜欢的任何
src
url 添加一个新脚本到页面即可。它被称为跨站脚本(或XSS )。在我看来,它引入的漏洞使得浏览器监管“同源”策略的所有其他尝试都变得毫无意义。他们只是想修补一条已经掉到脚踝处的裤子上的破洞。"Javascript is out, because most browser don't allow cross domain calls."
Unfortunately, Javascript is most definitely in. You just have to add a new script to the page with whatever
src
url you like. It's called Cross-Site Scripting (or XSS). IMO, the vulnerability it introduces renders moot all the other attempts by browsers to regulate a "same-origin" policy. They're just trying to patch a hole in a pair of pants that have already fallen down around your ankles.如果您对要向其发出跨域请求的服务器具有管理访问权限,则可以使其提供 Flash 跨域策略文件,以授予另一台或多台服务器跨域访问权限。然后,其他服务器需要使用 Flash 来发出跨域请求。
如果您正在寻找一些可以帮助您入门的东西,请查看开源 Forge 项目。它在 JavaScript 中公开了跨域 XmlHttpRequest API,因此您只需编写 JavaScript 代码:
http ://github.com/digitalbazaar/forge/blob/master/README
If you have administrative access to the server you will be making a cross-domain request to, then you can make it serve a Flash cross-domain policy file that grants another server (or servers) cross-domain access. Then that other server needs to use Flash to make its cross-domain requests.
If you are looking for something to help get you started, check out the opensource Forge project. It exposes a cross-domain XmlHttpRequest API in JavaScript so you only have to write JavaScript code:
http://github.com/digitalbazaar/forge/blob/master/README
Java 和 Flash 都支持
crossdomain.xml
文件,分别在 Oracle 和 Adobe 网站上进行了记录。W3C 正在制定采用不同方法的标准。当哪个系统实现这一点时,我无法预测。
Both Java and Flash support
crossdomain.xml
files, as documented on Oracle and Adobe sites respectively.W3C is working on a standard that takes a different approach. When that gets implemented by which systems, I cannot predict.
您必须坚持使用代理解决方案,因为 flash 和 java 与 javascript 具有相同的跨域限制。如果这仅供个人使用,据我所知,有一个选项可以使用 Flex 构建器和 falsh 播放器的调试器版本来发出跨域请求。
You will have to stick with the proxy solution because flash and java have the same cross-domain restrictions as javascript. If this is something that is only for personal use, there is an option as I know with the flex builder and the debugger version of the falsh player which can make cross-domain requests.