【问题标题】:RequestBuilder returns empty responseRequestBuilder 返回空响应
【发布时间】:2011-02-25 10:12:24
【问题描述】:

我在 GWT 的前端使用 RequestBuilder 向 Restlet Web 服务发送 HTTP GET 请求。但是,请求可以进入 Web 服务,并且 Web 服务返回一个字符串(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() 总是返回空。

提前致谢!

艾克

【问题讨论】:

  • 如果请求被触发,但如在 firebug 中看到的那样返回空响应,则您的服务器端代码存在问题。请您发布该代码吗?
  • 几个潜在问题。首先,确保 Firefox 未处于离线模式。什么是响应状态码,这个很关键。 500 表示您有服务器问题,404 表示您的端点错误,200 表示您有非 rpc 问题(在您的服务代码更深的地方)。

标签: gwt restlet


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您的问题是同源策略。所有请求中的协议、域和端口都必须与服务 GWT 应用程序的那些相同。如果您在 Eclipse 中的 8888 端口提供服务,而您的自定义服务器位于 8080 端口,这将不是小事。

    尝试将 apache 服务器配置为代理,例如对http://localhost/gwt-app.htmlhttp://localhost:8888/gwt-app.html 的请求以及对http://localhost:8080/* 的服务器的所有其他请求

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多