当我们想要调用Web服务时,我们遇到了从Web服务获取响应的问题。 我们正在使用KSOAP2库,当我们想要使用Content-Type text / xml获得普通的SOAPObject时,一切顺利,但现在我们需要从一个回复内容类型的动作获得响应:multipart / related。所以标准代码不起作用。
public SoapObject getDocuments(String id, String type)
{
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME_GETDOCUMENTS);
Request.addProperty("humres", id);
Request.addProperty("type", type);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(Request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try
{
androidHttpTransport.call(SOAP_ACTION_GETDOCUMENTS, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
return response;
}
catch(XmlPullParserException exPull)
{
exPull.printStackTrace();
return null;
}
catch(IOException exIO)
{
exIO.printStackTrace();
return null;
}
}
接下来是我们收到的错误
09-13 14:14:31.078: W/System.err(875): org.xmlpull.v1.XmlPullParserException: PI must not start with xml (position:unknown --=_1e3686ff8230e83d586a024e6feaaf4d
09-13 14:14:31.078: W/System.err(875): Content-Transfer-Encoding: 8bit
09-13 14:14:31.111: W/System.err(875): Content-Type: text/xml;
09-13 14:14:31.111: W/System.err(875): charset=UTF-8
09-13 14:14:31.111: W/System.err(875): @6:5 in java.io.InputStreamReader@406386b8)
09-13 14:14:31.111: W/System.err(875): at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
09-13 14:14:31.118: W/System.err(875): at org.kxml2.io.KXmlParser.error(KXmlParser.java:269)
09-13 14:14:31.118: W/System.err(875): at org.kxml2.io.KXmlParser.parseLegacy(KXmlParser.java:398)
09-13 14:14:31.118: W/System.err(875): at org.kxml2.io.KXmlParser.nextImpl(KXmlParser.java:366)
09-13 14:14:31.118: W/System.err(875): at org.kxml2.io.KXmlParser.next(KXmlParser.java:1378)
09-13 14:14:31.118: W/System.err(875): at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:1408)
09-13 14:14:31.118: W/System.err(875): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
09-13 14:14:31.129: W/System.err(875): at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
09-13 14:14:31.129: W/System.err(875): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:197)
09-13 14:14:31.129: W/System.err(875): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
09-13 14:14:31.129: W/System.err(875): at com.cx.pservices.WebserviceUbPlus.getInvoice(WebserviceUbPlus.java:133)
09-13 14:14:31.129: W/System.err(875): at com.cx.pservices.employer.facaturetab$Progress.doInBackground(facaturetab.java:346)
09-13 14:14:31.138: W/System.err(875): at com.cx.pservices.employer.facaturetab$Progress.doInBackground(facaturetab.java:1)
09-13 14:14:31.148: W/System.err(875): at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-13 14:14:31.148: W/System.err(875): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-13 14:14:31.158: W/System.err(875): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-13 14:14:31.158: W/System.err(875): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-13 14:14:31.158: W/System.err(875): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-13 14:14:31.158: W/System.err(875): at java.lang.Thread.run(Thread.java:1019)
响应XML
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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:Body>
<ns1:GetInvoiceResponse xmlns:ns1="UBplusOnlineWebservice">
<invoice xsi:type="xsd:string">
<resultxml>
<statuscode>100</statuscode>
<message>
<Invoice>
<DocumentId>05-000053</DocumentId>
<Amount>36.89</Amount>
<Date>2012-09-06 00:00:00</Date>
<Description>Factuur 22050003</Description>
</Invoice>
</message>
<attachments>1</attachments>
<filenames>
<filename>05-000053-05-22050003.pdf</filename>
</filenames>
</resultxml>
</invoice>
</ns1:GetInvoiceResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
也许很高兴知道我们除了
之外的原始数据HTTP/1.1 200 OK
Date: Thu, 13 Sep 2012 11:56:44 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
Set-Cookie: cisession=WDRVaFAxC2MAKAF1VjtbMw9sWjNUIgMnCDZXd1hzB2hYYwdkBgsFbl00AidQPwQlBG0GMlE0Xj1XJgZlVTJXYQ03UTUAO1E2UzYCPFRjBD5YM1VnUGcLPQBmAWRWY1s3D25aMFRmA2MIMVc9WGEHN1hpBzMGZAVhXWICJ1A%2FBCUEbQYwUTZePVcmBjxVcVdfDTdRZgA8USVTYgJ8VHUEJFhuVSFQPgtoAGEBPFYjWzUPa1onVDEDYghhVypYNgcyWCIHPgZtBSVdawJ2UD4EZwRnBjtRJF5yV3cGMFVzV18NN1FlAD1ROVNzAi1UPQR1WG9VYVAwC2MAcQFHVnFbYw8%2FWmFUZQN5CBtXcFh0B3FYTwdmBj0FYl0%2BAnFQKwRiBHkGMFEoXjZXJAZ9VWtXYQ0gUWMAeFFmUykCOlQvBCRYblUhUD4LaABgATxWI1tuDz1aelR0AwsIMldnWHQHaFh6B2MGIAV%2BXXICPlBtBGwEZgYyUTJeMFcxBmZVNlc0DWZRNgBjUSRTPQI2VDwEJFggVSFQYQsrAAwBYlZgW3YPPVorVDsDJwhpVzRYOgcjWC4HMQYp; path=/; domain=.ubplusonline.nl
Set-Cookie: cisession=C2dRbFc3C2NReVImAG1dNQZlWjNcKlVxCDZXdwArBGtWbQJhVVgCaQtiACVVOgorBG0PO1YzC2hVJFU2UDdQZg03UTUDOABnVDEEOlBnUmgLYFFjV2ALPVE3UjcANV0xBmdaMFxuVTUIMVc9ADkENFZnAjZVNwJmCzQAJVU6CisEbQ85VjELaFUkVW9QdFBYDTdRZgM%2FAHRUZQR6UHFScgs9USVXOQtoUTBSbwB1XTMGYlonXDlVNAhhVyoAbgQxViwCO1U%2BAiILPQB0VTsKaQRnDzJWIwsnVXVVY1B2UFgNN1FlAz4AaFR0BCtQOVIjCzxRZVc3C2NRIFIUACddZQY2WmFcbVUvCBtXcAAsBHJWQQJjVW4CZQtoAHNVLgpsBHkPOVYvC2NVJlUuUG5QZg0gUWMDewA3VC4EPFArUnILPVElVzkLaFExUm8AdV1oBjRaelx8VV0IMldnACwEa1Z0AmZVcwJ5CyQAPFVoCmIEZg87VjULZVUzVTVQM1AzDWZRNgNgAHs%3D; path=/; domain=.ubplusonline.nl
X-SOAP-Server: NuSOAP/0.9.5 (1.3)
Content-Encoding: gzip
Content-Length: 3176
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: multipart/related; type="text/xml"; boundary="=_5f570f873903a0a03b45f977ae3c4a2f"
--=_5f570f873903a0a03b45f977ae3c4a2f
Content-Transfer-Encoding: 8bit
Content-Type: text/xml;
charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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:Body><ns1:GetInvoiceResponse xmlns:ns1="UBplusOnlineWebservice"><invoice xsi:type="xsd:string"><resultxml>
<statuscode>100</statuscode>
<message>
<Invoice>
<DocumentId>05-000053</DocumentId>
<Amount>36.89</Amount>
<Date>2012-09-06 00:00:00</Date>
<Description>Factuur 22050003</Description>
</Invoice>
</message>
<attachments>1</attachments>
<filenames>
<filename>05-000053-05-22050003.pdf</filename>
</filenames>
</resultxml></invoice></ns1:GetInvoiceResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
--=_5f570f873903a0a03b45f977ae3c4a2f
Content-Transfer-Encoding: base64
Content-ID: <cc9034cb2aa23a6357e46d8f45e682d5>
Content-Type: application/pdf;
name=
Content-Disposition: attachment;
filename=
任何人都有想法如何解决这个问题?无论如何,无论如何