简体   繁体   中英

GWT interacting with restful architecture

I have a backend REST API and i have a front end with GWT. I'm on a network where my ip address is 192.168.1.4.

I've declared a constant URL as

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

with the ip 127.0.0.1, everything is working fine

but when i changing the ip to 192.168.1.4, the application is not working and i'm getting status code of 0.

The GWT app is on the web root same as the 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!!

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. In Chrome, add your ip addresses at tools | extensions | GWT Dev Plugin | options. In Firefox, it is at 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.

public static GWT.getHostPageBaseURL() is useful for prepending to paths of resources relative to the host page.

public static GWT.getModuleBaseURL() is useful for prepanding urls intended to be module-relative.

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; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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