RequestBuilder返回空响应

时间:2011-02-25 10:12:24

标签: gwt restlet

我在GWT的前端使用RequestBuilder向Restlet Web服务发送HTTP GET请求。但是,请求可以进入Web服务,Web服务返回一个String(格式为JSON)。问题是当我通过fireBug监视进程时没有返回响应。谁知道为什么?

以下是代码:

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()始终返回空。

提前致谢!

艾克

2 个答案:

答案 0 :(得分:1)

您是否在为发出请求的网页提供服务的同一主机和端口上调用Restlet服务器?

我猜你正在遇到http://en.wikipedia.org/wiki/Same_origin_policy

答案 1 :(得分:0)

您的问题是同源政策。您的所有请求中的协议,域和端口必须与提供GWT应用程序的请求相同。如果您在Eclipse中使用端口8888进行服务而您的自定义服务器位于端口8080,那么这将不是一件容易的事。

尝试将apache服务器配置为代理,例如http://localhost/gwt-app.html

请求http://localhost:8888/gwt-app.htmlhttp://localhost:8080/*以及服务器上的所有其他内容
相关问题