简体   繁体   English

我怎样才能绕过相同的原产地政策?

[英]How can i get around the same origin policy?

I need to use AJAX to get the content of another page located on a different server from the one the AJAX is loaded from.我需要使用 AJAX 来获取位于与加载 AJAX 的服务器不同的服务器上的另一个页面的内容。 The AJAX needs to send a POST request then return the result. AJAX 需要发送一个 POST 请求然后返回结果。 how can i do this?我怎样才能做到这一点?

Set up proxy on your own server.在您自己的服务器上设置代理。 Have your server call theirs and return the result.让您的服务器调用他们的服务器并返回结果。

if you control both servers, you can use one of the HTTP header fields for cross-origin resource sharing :如果您控制两台服务器,则可以使用 HTTP 标头字段之一进行跨域资源共享

http://www.petefreitag.com/item/703.cfm http://www.petefreitag.com/item/703.cfm

https://developer.mozilla.org/En/HTTP_access_control https://developer.mozilla.org/En/HTTP_access_control

There is no way to go around that policy.没有办法绕过该政策。 This policy is there for very good reasons.这项政策有很好的理由。 That is also no problem as long as you're in control over the web application.只要您能够控制 Web 应用程序,这也没有问题。 You could simply redirect the call to the other server from your webserver and pass the result.您可以简单地将呼叫从您的网络服务器重定向到另一台服务器并传递结果。 This would work out like a proxy.这将像代理一样工作。

If you want to do that on the client and cross browser, you need some cooperation from the other server.如果您想在客户端和跨浏览器上执行此操作,则需要其他服务器的一些配合。

Either by:或者通过:

1) using JSONP (inject a script tag with a callback function) 1)使用JSONP(注入带有回调函数的脚本标签)
Only GET calls are possible though.不过,只有 GET 调用是可能的。
Security is an issue as the script has access to all resources in that page(data, cookies, ...).安全性是一个问题,因为脚本可以访问该页面中的所有资源(数据、cookie、...)。
Here's a post that explain how to sandbox them and keep the data in your page safe.这是一篇文章,解释了如何对它们进行沙箱处理并确保页面中的数据安全。

2) POST looks possible using Kris Zip's window.name technique 2) POST 看起来可能使用 Kris Zip 的window.name 技术

If the cooperation from the other server is impossible, the server proxy as described in other answers is, to my knowledge, the only option left.如果无法与其他服务器合作,据我所知,其他答案中描述的服务器代理是唯一的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM