AsyncHttpClient - 奇怪的响应,比如不正确的字符集

AsyncHttpClient - Strange response, like incorrect charset

在我昨天遇到这个问题之前,这个库对我来说工作得很好。我尝试了 1.4.5 和 1.4 版本。8.I 在真实设备、模拟器上进行了测试。我还创建了一个新项目,只连接到 Google:

AsyncHttpClient client = new AsyncHttpClient();
client.get("https://www.google.com", new AsyncHttpResponseHandler() {

    @Override
    public void onSuccess(int statusCode, Header[] headers, byte[] response) {
        // called when response HTTP status is "200 OK"
        Log.e("TEST", new String(response));
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
        // called when response HTTP status is "4XX" (eg. 401, 403, 404)
    }
});

然后响应:������������������}iw6���� ������H-��%��q��7q����������bL��4IyS������$A����<9��S7"v���� 6x.f.Vz.9.I.{..N.Xa..<.P&i. ��Ě8��m������o��( �N]Cq� ��P{��qऴa��Ʊ��r��ؚ4͉Ӹ c��H��t����M�pJ��c�3��+nj��������l'L�tj7�0vZ��a����/M����4 ��<�7�Mg��4�1q�q���c�9��J�Մ����; ?ϱB����4��4����Nb��^��0)��&L�Ў��qh��i����an��³1�� L��춢��Q��ad(,!��O ��w��x������1��b��9��M-��������U��l����������`��Ϣ����{���� �Ӄ 帮帮我,谢谢

这是 AsyncHttpClient 中的已知问题(请参阅 https://github.com/loopj/android-async-http/issues/932)。您可以禁用 gzip 作为临时解决方法:

AsyncHttpClient client = new AsyncHttpClient();
client.addHeader("Accept-Encoding", "identity"); // disable gzip
client.get(...)