HttpClient Android supports gzip

This commit is contained in:
gyf19 2015-06-03 19:41:14 +08:00
parent 883f250f6a
commit 164e4c8314
1 changed files with 15 additions and 4 deletions

View File

@ -28,6 +28,8 @@ import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
@ -260,11 +262,20 @@ public class Cocos2dxHttpURLConnection
}
static byte[] getResponseContent(HttpURLConnection http) {
DataInputStream in;
InputStream in;
try {
in = new DataInputStream(http.getInputStream());
in = http.getInputStream();
String contentEncoding = http.getContentEncoding();
if (contentEncoding != null) {
if(contentEncoding.equalsIgnoreCase("gzip")){
in = new GZIPInputStream(http.getInputStream()); //reads 2 bytes to determine GZIP stream!
}
else if(contentEncoding.equalsIgnoreCase("deflate")){
in = new InflaterInputStream(http.getInputStream());
}
}
} catch (IOException e) {
in = new DataInputStream(http.getErrorStream());
in = http.getErrorStream();
} catch (Exception e) {
Log.e("Cocos2dxHttpURLConnection exception", e.toString());
return null;