简体   繁体   English

GWT与宁静的架构互动

[英]GWT interacting with restful architecture

I have a backend REST API and i have a front end with GWT. 我有一个后端REST API,我有一个GWT的前端。 I'm on a network where my ip address is 192.168.1.4. 我在网络上,我的IP地址是192.168.1.4。

I've declared a constant URL as 我已经声明了一个常量URL

public static final String DomainName="http://127.0.0.1/recess/restApp/";

with the ip 127.0.0.1, everything is working fine 使用ip 127.0.0.1,一切正常

but when i changing the ip to 192.168.1.4, the application is not working and i'm getting status code of 0. 但是当我将ip更改为192.168.1.4时,应用程序无法运行,我的状态代码为0。

The GWT app is on the web root same as the REST API. GWT应用程序位于Web根目录,与REST API相同。

In fact, this cannot be a same origin policy problem because its a web service?? 事实上,这不是一个相同的原始政策问题,因为它的网络服务?

Anyone has an idea about this?? 有人对此有所了解吗?

I'm using xampp and the GWT project is in htdocs same as the REST API!! 我正在使用xampp,GWT项目在htdocs中与REST API相同!

It certainly sounds like you are running into a sandbox policy forbidding external connections. 这听起来好像是你遇到了沙箱政策,禁止外部连接。

One policy you may be running into is the GWT browser add-on connection limitation. 您可能遇到的一个策略是GWT浏览器附加连接限制。 In Chrome, add your ip addresses at tools | 在Chrome中,在工具中添加您的IP地址 extensions | 扩展| GWT Dev Plugin | GWT Dev插件| options. 选项。 In Firefox, it is at Tools | 在Firefox中,它位于Tools | Add-ons | 附加组件| Extensions | 扩展| Google... | 谷歌... | Options 选项

May I suggest that instead of using hard coded urls, to conform to the single source policy, you may want to use the exact url that loaded the web page. 我可以建议您使用加载网页的确切网址,而不是使用硬编码网址,以符合单一来源政策。 The web toolkit provides a mechanism for doing just that. Web工具包提供了执行此操作的机制。

public static GWT.getHostPageBaseURL() is useful for prepending to paths of resources relative to the host page. public static GWT.getHostPageBaseURL()用于预先设置相对于主机页面的资源路径。

public static GWT.getModuleBaseURL() is useful for prepanding urls intended to be module-relative. public static GWT.getModuleBaseURL()用于预先准备与模块相关的URL。

http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/core/client/GWT.html#getHostPageBaseURL () http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/core/client/GWT.html#getHostPageBaseURL ()

I'm afraid this is a Same-Origin Policy violation: if you ask your browser to load some URL using XMLHttpRequest (or in GWT a RequestBuilder ), then that URL has to be on the same origin as the page trying to access it; 我担心这是RequestBuilder策略违规:如果您要求浏览器使用XMLHttpRequest加载某些URL(或在GWT中使用RequestBuilder ),那么该URL必须与尝试访问它的页面位于同一个上; unless the browser supports CORS (all, except IE; at least until IE10 is out the door) and the server you're trying to reach sends the appropriate HTTP headers to allow the cross-origin connection. 除非浏览器支持CORS (除IE之外的所有内容;至少在IE10出门之前),并且您尝试访问的服务器发送适当的HTTP标头以允许跨源连接。

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

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