解码base64 gzip .net webservice

时间:2016-12-05 20:07:49

标签: android web-services unicode gzip

我正在使用带有ksoap2的Android Studio(由http://www.wsdl2code.com制作的包装器) 使用.net网络服务。 此Web服务返回一个字符串,该字符串由包含序列化XML数据集的gzip字符串的base64编码。

我无法找到正确的XML字符串。

Android代码如下所示:

        byte[] data = Base64.decode(xmlO, Base64.DEFAULT);
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
...
        GZIPInputStream gzip = new GZIPInputStream(bais);
        InputStreamReader reader = new InputStreamReader(gzip,"US-ASCII");
        int n = 0;
        char[] buffer = new char[1024 * 8];
        StringWriter writer = new StringWriter();
        while (-1 != (n = reader.read(buffer))) writer.write(buffer, 0, n);
        decodedXML= writer.toString();
        writer.close();
....

我尝试过不同的ByteArrayInputStream / InputStreamReader配置。

.NET解码算法如下所示:

     Dim ArIN() = Convert.FromBase64String(_inputString)
            Using decomStream As IO.MemoryStream = New IO.MemoryStream(ArIN)
                Using hgs As IO.Compression.GZipStream = New IO.Compression.GZipStream(decomStream, IO.Compression.CompressionMode.Decompress)
                    Dim sr As New IO.StreamReader(hgs, System.Text.Encoding.Unicode, True)
                    _inputString = ""

                    strDS = sr.ReadToEnd
                    sr.Close()
                    hgs.Close()
                End Using
            End Using

有什么建议吗? 遵循base64字符串:

H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcpl
VmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ih7/Gi9+
jfzXuPo1nv4a2a/R0v9f01/tr3H0a/zGv0bya6T03+Nf492v0fwaj+j/019jTt8tqE36axS/xuzX
+OzX+Cj67kf0/TtqV/4aS3oLrcJPHjFEfD6n1u2vsaJP7tJ/V/zfmP5/j/6tfo3617igT/d+jR36
b5d++71/jS9+jefUh8OjC3dB/84UF8BfE4xlB/fm19imnwV9UlMfDf3/nNpv098Vff5I4W0HsD7y
6OHTJK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+rykEdb83e9Oc/OS/hvT/xEbfJs+wbcX9ElLc9MyvPAdf0yb
sP6QMeHNlr579mvIauj7jCqltj8cLE+ox5LWUcGt+XvheMR9giOmDKP6NT5j/+/+r3FIXBiTAnz/
gL//CXovI6w/Y941f5/av/HeBX3yGeuBQ+brl8Qdn/G35q9XtpV555xGVpEMVtT3F78GVvrluzVR
5jPl6R8+J7z6Nb4ivfF+tD38NX5f4pzy14Cczen7p/Re82u8pU9f09gyoicoWnt/nxJma3rj9yUJ
2iO5/v1734zpjXc6yz8sKryify8Ig3ekN2qiQvW15OHo1/j9fo2tX+P3+DV+V5rD/V/jDo3x6tf4
5Nf43f5fMhLw4vuN5pgl5Xf/oeJ/7Enr2FqaF/z2+8/HMf2OXqsfslR1R5HxOHKyG6IzCpaLrzuW
3R/qWGDxlr/GEx4LNOZr/vsH9L3ow/cbhclmvz/2+A58cEVaJuOeX3OLo1/j/wEtR5SU4GoAAA==

1 个答案:

答案 0 :(得分:0)

InputStreamReader reader = new InputStreamReader(gzip,"US-ASCII");

Dim sr As New IO.StreamReader(hgs, System.Text.Encoding.Unicode, True)

US-ASCIIEncoding.Unicode不是相同的编码。

Encoding.Unicode是.NET引用UTF-16LE编码的误导方式。从JVM,new InputStreamReader(gzip, "UTF-16LE");应该以与.NET代码相同的方式处理字节。