【问题标题】:Getting response status code 0 in SmartGWT webservice call using json使用 json 在 SmartGWT Web 服务调用中获取响应状态码 0
【发布时间】:2012-06-14 20:58:50
【问题描述】:

我已经使用 SmartGWT 开发了应用程序。现在我需要使用 json 调用 webservice 到另一个应用程序,该应用程序部署在另一个服务器中以提交用户名和密码。当我使用 url 和 POST 方法发出请求时,响应状态码为 0,响应文本为空白。

这是我的代码,

public void sendRequest() throws Exception {

    // Get login json data to be sent to server.
    String strData = createLoginReqPacket();
    String url = "some url";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    builder.setHeader("Content-Type", "application/json");
    builder.setHeader("Content-Length", strData.length() + "");

    Request response = builder.sendRequest(strData, new RequestCallback() {

        @Override
        public void onResponseReceived(Request request, Response response) {

            int statusCode = response.getStatusCode();
            System.out.println("Response code ----"+response.getStatusCode()+"");

            if (statusCode == Response.SC_OK) {
                String responseBody = response.getText();
                System.out.println("Respose :" + responseBody);
                // do something with the response
            } else {
                GWT.log("Response error at server side ----",null);
                // do in case of server error
            }

        }// end of method.

        @Override
        public void onError(Request request, Throwable exception) {
            GWT.log("**** Error in service call ******",null);
        }// end of method.
    });

    builder.send();
}// end of send request.

请问有人知道解决办法吗?


因为我是 GWT/SmartGwt 的新手,所以我不太关心它。

@ModeEngage 没有理由使用 GWT 类(RequestBuilder),但我不知道使用数据源。你能提供参考或材料吗??

当我在 chrome 浏览器中运行它时,我在错误控制台中得到以下信息。

XMLHttpRequest 无法加载 http:// "requested Url" 。 Access-Control-Allow-Origin 不允许 Origin http:// "localhost:8888"。

有什么解决办法???

【问题讨论】:

  • 在没有 GWT 的情况下拨打电话时,Web 服务是否响应正常?
  • 您是否有理由使用 GWT 类 (RequestBuilder) 而不是 SmartGWT 数据源?
  • 我认为他的 JSON 服务提供了与 smartgwt 无关的信息。

标签: json web-services smartgwt


【解决方案1】:

我相信这是由防火墙引起的。我已经进行了一些测试,这是最可能的解释。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多