【问题标题】:How to parse xml response from soap of type base64binary in android?如何在android中解析来自base64binary类型soap的xml响应?
【发布时间】:2018-02-16 06:43:12
【问题描述】:

XML 响应。
试图获取file 的值,它的类型为base64binary

 <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:GetFileResponse>
            <file xsi:type="xsd:base64Binary">/9j/4AAQSkZJRgABAQAAAQABAAA=</file>
        </ns1:GetFileResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

用于获取和解析上述响应的 Android 代码。我正在使用下面的代码。

protected Void doInBackground(Void... params) {

        String URL = "http://ngage.services/dss/albertsons/xmds.php?v=4&wsdl/GetFile";

        //for linear parameter
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_GET_FILE);
        request.addProperty("serverKey", "nitro"); // adding method property here serially
        request.addProperty("hardwareKey", "01a5de64f888b0c5a286ff821695cdfd41ad08"); // adding method property here serially
        request.addProperty("fileId", "27");
        request.addProperty("fileType", "media");
        request.addProperty("chunkOffset", "0");
        request.addProperty("chunkSize", "207672");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            androidHttpTransport.call(SOAP_ACTION_GET_FILE, envelope);
        } catch (Exception e) {
            e.printStackTrace();
        }

        SoapObject result;

        result = (SoapObject) envelope.bodyIn;

        if (result != null) {
            String encodedImage = result.getProperty("file").toString();
            Log.v("TAG", encodedImage);
            byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
            decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,
                    decodedString.length);


        }
        return null;
    }

编码后的图像值应该是/9j/4AAQSkZJRgABAQAAAQABAAA=,但我得到的值是base64Binary{}

请帮我以正确的方式解析它

【问题讨论】:

  • 你能发布你的 SOAP_ACTION_GET_FILE 值吗
  • SAOP_ACTION_GET_FILE = urn:xmds#GetFile
  • 我不是在 标签中获取值。除了得到完整的响应。
  • result.getProperty(0).toString();试试这个
  • 感谢您的帮助 :)

标签: java android xml-parsing android-ksoap2


【解决方案1】:

我传递的参数拼写错误。代替chunkSize,它应该是chuckSize。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多