我想使用由 GZIP 压缩的带有 ksoap2 的 BasicHttp WCF Web 服务。
有没有办法在 Android 版本的 ksoap2 (http://code.google.com/p/ksoap2-android/) 中做到这一点,还是有其他方法?
我想使用由 GZIP 压缩的带有 ksoap2 的 BasicHttp WCF Web 服务。
有没有办法在 Android 版本的 ksoap2 (http://code.google.com/p/ksoap2-android/) 中做到这一点,还是有其他方法?
我创建了一个扩展 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”传递给解析器。如果有更好的编码方式,我会很高兴知道。.))