绕过GWT同源策略 [英] Getting around GWT Same Origin Policy

查看:141
本文介绍了绕过GWT同源策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在此链接上执行建议
http:// raibledesigns。 com / rd / entry / how_to_do_cross_domain
我在服务器上的现有Servlet看起来像

  @SuppressWarnings serial)
public class ContactsServiceImpl extends RemoteServiceServlet implements ContactsService
{
...

我如何修改这个以使跨域正常工作。我需要在客户端进行任何更改吗?

解决方案

这不是GWT同源策略 - 它是浏览器本身!浏览器通常不会允许任何XHR调用传出到与加载页面的服务器不同的服务器。



您提到的链接可让您服务器充当代理 - 这是让客户与另一台服务器交谈的一种方式。他们所采取的步骤(创建一个转发请求的servlet,将其配置为指向您要使用的其他服务器)不需要对客户端进行更改。



另一个选项是使用跨源资源共享 - 服务器的一种方式指定允许浏览器联系它,即使跨域。问题在于:并非所有的浏览器都支持它。

I am trying to implement the work around suggested on this link http://raibledesigns.com/rd/entry/how_to_do_cross_domain My existing Servlet on my server looks like

@SuppressWarnings("serial")
public class ContactsServiceImpl extends RemoteServiceServlet  implements ContactsService   
{
 ...

How do I modify this to get the cross domain to work. Do I need to make any changes on the client side?

解决方案

It isn't the GWT Same Origin Policy - it is the browser itself! The browser won't normally allow any XHR call to go out to a server that isn't the same server the page was loaded from.

The link you mentioned lets your server act as a proxy - thats one way to let the client talk to another server. The steps they take (create a servlet that forwards requests, configure it to point at the other server you want to use) do not require changes to the client.

Another option is to use the Cross Origin Resource Sharing - a way for the server to specify that the browser is allowed to contact it, even across domains. The catch: not all browsers support it.

这篇关于绕过GWT同源策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆