ksoap2调用webservice接口的时候报的错,网上找了很久的答案没找到,后来自己用SoapUI测试工具测了下,发现返回的数据居然是这样子的:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:8fe57e81-8d1d-49ef-9b77-99943e902643"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Content-Length: 516
Date: Thu, 03 May 2018 00:25:07 GMT
--uuid:8fe57e81-8d1d-49ef-9b77-99943e902643
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:putDocumentResponse xmlns:ns2="http://xxxx.com/"><LBEResult><message>失败</message><result>-2</result></LBEResult></ns2:putDocumentResponse></soap:Body></soap:Envelope>
--uuid:8fe57e81-8d1d-49ef-9b77-99943e902643--真TM坑!body的结构并不是xml的格式,前后多了两串字符串,什么--uuid这个,导致ksoap2解析失败,服务端说不知道怎么改掉,只能放弃ksoap2了,改用HttpURLConnection自己请求接口,再用XmlPullParser解析数据,问题解决了。
本文介绍了一种使用ksoap2调用WebService接口时遇到的问题及解决方案。问题表现为返回的数据格式不正确,导致ksoap2无法解析。最终通过采用HttpURLConnection结合XmlPullParser的方式成功获取并解析数据。
9844

被折叠的 条评论
为什么被折叠?



