我看到其他一些用户也遇到了同样的问题,但说实话,这些答案对我没有帮助。
我有一个连接到 PHP Web 服务(使用 NuSOAP)的 Android 客户端,并且在本地一切正常。当我部署 Web 服务并更新客户端上的变量时,出现以下错误:
org.xmlpull.v1.xmlpullparserexception: unexpected type (position: END_DOCUMENT null@1:0 in java.io.InputStreamReader@44f11f30)
这种情况是随机发生的 - 例如,对于登录,如果第一次尝试是“密码错误”(成功连接到网络服务),第二次尝试时我会收到该错误。如果它被接受,我会强制关闭应用程序(我开始另一个 Activity ),我想这是因为这个问题。
我不知道问题出在哪里,因为我不手动处理任何 XML 文件,而且我的 WDSL 很好,如您所见 here
我的连接字符串如下:
private static final String URL = "http://apkitchen.voku-online.de:8080/webs.php";
private static final String NAMESPACE = "urn:hellowsdl";
final String SOAP_ACTION = "urn:hellowsdl#auth";
final String METHOD_NAME = "auth";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
我的完整连接功能是:
public Object soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL)
throws IOException, XmlPullParserException {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", "Maxxd");
request.addProperty("password", "xxxx");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
return result;
}
老实说,我不知道为什么会发生这种情况......有什么帮助吗?
找到了问题(但没有找到解决方案...)
我转储了响应 xml 文件,看起来它是由 mall 形成的:
<SOAP-ENV:Envelope 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:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:authResponse xmlns:ns1="urn:hellowsdl">
<return xsi:type="xsd:string">0</return>
</ns1:authResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<!..................
信封本身没问题,但没有结束评论标签...我该如何解决这个问题?
最佳答案
看起来这是 API 级别 <9 上的 KSOAP2 android 实现的问题。
已解决
System.setProperty("http.keepAlive", "false");
我希望这对某人有帮助,因为我看到很多人都有同样的问题。
关于java - 使用 KSOAP2 连接到 Web 服务 - 获取 XmlPullParserException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6747161/