开发者

RequestBuilder returns empty response

开发者 https://www.devze.com 2023-02-13 22:35 出处:网络
I am using RequestBuilder on the front end of GWT to send a HTTP GET request to a Restlet Web Service. However, the request can get into the web开发者_JAVA百科 service and the web service return a Str

I am using RequestBuilder on the front end of GWT to send a HTTP GET request to a Restlet Web Service. However, the request can get into the web开发者_JAVA百科 service and the web service return a String (in the format of JSON). The problem is no response is returned when I monitor the process through fireBug. Anybody knows why?

Here is the code:

String url = "http://localhost:8080/Books";

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

try {
  builder.sendRequest(null, new RequestCallback() {

    public void onError(Request request, Throwable exception) 
    {
      exception.printStackTrace();

      Window.alert("fail - " + exception.getMessage());
    }

    public void onResponseReceived(Request request, Response response) 
    {

      Window.alert("success - " + response.getText());
    }
  });
} catch (RequestException e) 
{
  e.printStackTrace();
}

response.getText() always return empty.

Thanks in advance!

Ike


Do you do your call to a Restlet server on the same host and port that served the webpage that makes the request ?

I am guessing you are running into http://en.wikipedia.org/wiki/Same_origin_policy


Your problem is the Same Origin Policy. The protocol, domain and port in all your requests must be the same as those where your GWT app is being served. If you're serving in Eclipse at port 8888 and your custom server is at port 8080, this won't be trivial.

Try configuring an apache server to proxy e.g. requests to http://localhost/gwt-app.html to http://localhost:8888/gwt-app.html and everything else to your server at http://localhost:8080/*

0

精彩评论

暂无评论...
验证码 换一张
取 消