AsyncHttpClient发布并获取JSON响应

时间:2017-05-09 11:36:48

标签: java android json asynchttpclient

我必须将JSON发布到服务器,服务器会检索另一个。我试过这个,但它没有用。当我调试时,我从未在Success或onFailure上看到登录:

       String url = "https://*******/sessions";


        JSONObject requestObject = new JSONObject();
        try {
            requestObject.put("company", "TEST");
            requestObject.put("user", "*****");
            requestObject.put("secure_password", "8ce241e1ed84937ee48322b170b9b18c2");
            requestObject.put("secure_device_id", "C4CA4238A0B923820DCC509A6F75849B");
        } catch (JSONException e) {
            e.printStackTrace();
        }


//        JSONObject jsonParams = new JSONObject();
//        jsonParams.put("notes", "Test api support");
        StringEntity entity = null;
        try {
            entity = new StringEntity(requestObject.toString());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        client.post(this, url, entity, "application/json",
                new AsyncHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                        String res = responseBody.toString();
                        Log.e("response " , res);
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

                    }
                });

我如何获得回复正文?

1 个答案:

答案 0 :(得分:1)

我不清楚你在问什么,但你永远不会看到答案,因为你无法将reponseBody转换为String res = responseBody.toString();String res = new String(responseBody);这样的字符串。< / p>

改为 $(".comment:nth-child(n+3)").slideToggle();

如果这不是问题,请更新您的问题,我会更新我的答案。