【问题标题】:XML Response not showing in GWT from external SOLR server?XML 响应未显示在来自外部 SOLR 服务器的 GWT 中?
【发布时间】:2012-02-14 20:41:19
【问题描述】:

我已经开发了一个 GWT 应用程序,并且还在 localhost 机器上安装了一个 Apache Solr 服务器。

Solr 工作正常,查询返回所需结果。

现在为了将结果嵌入到我的 GWT 应用程序中,我使用 GWT 的 RequestBuilder 向 Solr 服务器发送一个 http 请求。

查询已到达 Solr,因为我可以在命令提示符中查看它。

在 GWT 端,请求成功,因为我的 onResponseRecieved() 被调用。但是响应的大小是0,状态码也是0。

我找不到问题出在哪里。

此外,如果存在同源策略,则应该运行 onError() 方法,但它不是。

以下是我的发送和处理代码

String url = "http://localhost:8983/solr/select/?q=bname:"+whatBox.getText()+"&version=2.2&start=0&rows=10&indent=on";
        RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
        System.out.println("here");
        try{
            Request req = rb.sendRequest(null, new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    System.out.println("in res");
                    System.out.println(response.getHeadersAsString());
                    RootPanel.get("content").clear();
                    RootPanel.get("content").add(new Label(response.getText()));    
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    // TODO Auto-generated method stub
                    System.out.println("error");
                }
            });

        }catch(RequestException e){
            e.printStackTrace();
        }

任何帮助将不胜感激!

【问题讨论】:

    标签: xml gwt solr


    【解决方案1】:

    我认为你违反了SOP rules。为了避免它们,我建议您使用JsonpRequestBuilder 而不是使用RequestBuilders。还可以看看一个非常有用的社区 wiki:Ways to circumvent the same-origin policyHow the Same Origin Policy does affect GWT?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多