Android 使用 async-http-library 的 GET 请求的 http 响应中的 GZip 内容

GZipped content in http response of GET request using async-http-library for Android

我正在尝试使用 Android-Async-http library in my app. Here 访问 Google 的地理编码 API 是我的请求,下面是响应:

����������������UMo��0��WX>Ӫ i{����UJ��$��J�� mπ%��===��������B��R��}����#4��.��d��{��$��b��D��V<��<���� ��w*y��q����y5����o������

这里是AsyncHttpResponseHandler的成功回调方法。

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
    if (statusCode == HttpStatus.SC_OK) {
        try {
            String response = new String(responseBody);
            //String response = new String(responseBody, "UTF-8"); //this is also giving junk reponse
            Log.v("SUCCESS RESPONSE", response);
            networkCallback.onSuccess(response);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

为什么我收到的回复是垃圾邮件?我如何获得正确的回应?

试试这个:

   @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            MyLog.log(TAG, response.toString());
            // if is Jsonobjec     
            }

 @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            super.onSuccess(statusCode, headers, response);
             MyLog.log(TAG, response.toString());
            // if is JsonArray    
        }

或者您想要获取响应字符串:

 @Override
        public void onSuccess(int statusCode, Header[] headers, String responseString) {
            super.onSuccess(statusCode, headers, responseString);
        }

二手

 compile 'com.loopj.android:android-async-http:1.4.9' 

而不是 1.4.5