WLResourceRequest onSuccess 抛出错误

WLResourceRequest onSuccess throws error

我在 WLResourceRequest 的 onsuccess 回调中收到错误,错误如下。

com.sun.jdi.InternalException : Unexpected JDWP Error: 14 Cannot evaluate com.worklight.wlclient.api.WLResponse.toString()

为什么会出现这个错误?有没有办法跳过这个。

我使用的代码是

它工作正常我在使用时得到响应 WLHttpResponseListener 而不是 WLResponseListener。

wlResponse.getResponseText();给出空响应。

 WLResourceRequest request = new WLResourceRequest("Actual server path here", GET);
      request.addHeader(new BasicHeader("IfAnyHeader", "here"));
    request.send(new ResponseListener());
 private class ResponseListener implements WLResponseListener {

        @Override
        public void onSuccess(WLResponse wlResponse) {

            responseCode = wlResponse.getStatus();
            final String result = wlResponse.getResponseText();
      }

        @Override
        public void onFailure(WLFailResponse wlFailResponse) {

            responseCode = wlFailResponse.getStatus();
            final String result = wlFailResponse.getResponseText();
}

我在 onSuccess 方法上收到错误... wlResponse.getResponseText();总是空的。

WLResponseListener 支持 WLClient.invokeProcedure。

http://www.ibm.com/support/knowledgecenter/en/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjava-worklight-j2me/html/com/worklight/wlclient/api/WLResponseListener.html

WLHTTPResponseListener 支持发送 WLResourceRequests http://www.ibm.com/support/knowledgecenter/en/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjava-worklight-android-native/html/com/worklight/wlclient/api/WLHttpResponseListener.html

由于您使用的是 WLResourceRequest(最佳实践),因此这是预期的行为。

我终于找到了这个问题的解决方案。

     request.send( new WLHttpResponseListener() {
                    @Override
                    public void onSuccess(HttpResponse httpResponse) {
                        BufferedReader reader = null;
                        try {

    //                        responseCode = httpResponse.getStatusLine();
                            WLResponse wlResponse=new WLResponse(httpResponse);

                            int responseCode=wlResponse.getStatus();


                            reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
// used a function to convert reader to string
                            final String result = entityToString(reader);

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

                    @Override
                    public void onFailure(HttpResponse httpResponse, Exception e) {
                        BufferedReader reader = null;
                        try {



                            responseCode = new WLFailResponse(new WLResponse(httpResponse)).getStatus();

                            reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
                            String result = entityToString(reader);

                        } catch (IOException eec) {
                            e.printStackTrace();
                        }

                    }
                });