Reputation: 644
I am hitting the following url from my android device.
Response: ������������������]�r�8�}ϯ@e?䋕�}ɗ j����%OO(@�q3���*b�a"�g�o�K��%Y]�em�,uGd8m�ātu��]������/�c���W�_����
B���M��;v�������q:��fA�[8KR�����lZ?[t]�JL���`�������G1����h䬑��T[}E�y�]qt�_xl��.��e/v�o���H
For getting the YouTube Videos List.It was working fine before but sometimes its response is not valid while hitting from browsers it works well.
Please help me !!
Upvotes: 1
Views: 447
Reputation: 644
I found the solution i was using the loop j library (for http request) old version
just changes
compile 'com.loopj.android:android-async-http:1.4.8'
to
compile 'com.loopj.android:android-async-http:1.4.9'
it solved my problem
Upvotes: 1
Reputation: 3497
Please see my related question here (but in C#
) and the answers on it in order to understand what I mean. Then you have to search example fordecompress gzip android
and look at the existing resources to accomplish this.
Please keep in mind, that the API does not always send the response in gzip-format or not. So please do a check if the response is really in gzip.
For the plain decompression you can use the following method:
public static String decompress(byte[] compressed) throws IOException {
final int BUFFER_SIZE = 32;
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(bis, BUFFER_SIZE);
StringBuilder s = new StringBuilder();
byte[] data = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = gis.read(data)) != -1) {
s.append(new String(data, 0, bytesRead));
}
gis.close();
bis.close();
return s.toString();
}
(this code was taken from Vyshnavi's answer)
Upvotes: 0