我想通过ksoap2使用GZIP服务,它由BasicHttp压缩。
有没有办法在安卓版本的ksoap2 (http://code.google.com/p/ksoap2-android/)中做到这一点,还是有别的办法?
发布于 2011-06-10 21:09:26
我创建了一个扩展HTTPTransportSe的类,覆盖了call()方法,并将这一行代码添加到代码中(摘自此处的https://github.com/mosabua/ksoap2-android/blob/master/ksoap2-j2se/src/main/java/org/ksoap2/transport/HttpTransportSE.java)
connection.setRequestProperty("Accept-Encoding","[Here you have to put the encoding]");然后,当我获得InputStream时,我使用retHeaders变量来检查是否有编码。
if (retHeaders != null){
Iterator it = retHeaders.iterator();
boolean found = false;
String encoding = "";
while (it.hasNext()){
HeaderProperty temp = (HeaderProperty) it.next();
if (temp.getKey().contentEquals("content-encoding")){
found = true;
encoding = temp.getValue();
}
}
if (found){
is = new GZIPInputStream(is, new Inflater(true));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[256];
while (true) {
int rd = is.read(buf, 0, 256);
if (rd == -1)
break;
bos.write(buf, 0, rd);
}
bos.flush();
buf = bos.toByteArray();
is.close();
is = new ByteArrayInputStream(buf);
}
}
parseResponse(envelope, is);然后,您必须将"is“传递给解析器。如果有更好的编码方式,我很乐意知道。.))
https://stackoverflow.com/questions/4974963
复制相似问题