我使用下面显示的代码从我们的Gzip服务器打开数据。我的代码是否已经支持Gzip(也许这已经由android完成了,而不是由我的java程序完成),还是我必须添加/更改smth。?我如何检查它是否使用Gzip?对于我的观点,下载有点慢。Android:默认支持Gzip/Http?
private static InputStream OpenHttpConnection(String urlString) throws IOException {
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
if(in == null)
throw new IOException("No data");
}
} catch (Exception ex) {
throw new IOException("Error connecting");
}
return in;
}
对于LAN嗅探器+1。例如,您可以尝试Wireshark。 – 2010-09-06 13:04:43