I want to consume a BasicHttp WCF web service with ksoap2 that is compressed by GZIP.
Is there a way to do this in the Android version of ksoap2 (http://code.google.com/p/ksoap2-android/) or is there another way?
I want to consume a BasicHttp WCF web service with ksoap2 that is compressed by GZIP.
Is there a way to do this in the Android version of ksoap2 (http://code.google.com/p/ksoap2-android/) or is there another way?
I have create a class that extend the HTTPTransportSe and overrode the call() method and added this line to the code (taken from here 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]");
Then when I get the InputStream I use the retHeaders variable to check if there's the encoding.
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);
And then you have to pass the "is" to the parser. If there's a better way to code it I will happy to know about it. .))