使用KSOAP2连接到Web服务 - 获取XmlPullParserException [英] Connecting to Web Service with KSOAP2 - getting XmlPullParserException

查看:122
本文介绍了使用KSOAP2连接到Web服务 - 获取XmlPullParserException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到其他一些用户遇到同样的问题,但老实说答案并没有帮助我。

I saw some other users with the same problem but honestly the answers didnt helped me.

我有一个连接到PHP Web服务的android客户端(使用NuSOAP) ),本地一切正常。当我部署我的web服务并更新客户端上的变量时,我收到以下错误:

I have a android client which connects to a PHP Web Service (using NuSOAP), and locally everything works fine. When I deployed my webservice and updated the variables on the client, I'm getting the following error:


org.xmlpull.v1.xmlpullparserexception :意外类型(位置:
END_DOCUMENT null @ 1:0 in java.io.InputStreamReader@44f11f30)

org.xmlpull.v1.xmlpullparserexception: unexpected type (position: END_DOCUMENT null@1:0 in java.io.InputStreamReader@44f11f30)

这种情况发生随机 - 例如,对于登录,如果第一次尝试是错误的密码(成功连接到Web服务)第二次尝试我得到该错误。如果它被接受了我的应用程序关闭(我开始另一个活动)我想这是因为那个问题。

This happens randomly - for example, for login, if the first try is "wrong password" (sucessfull connection to the web service) the second try I get that error. If it's accepted I got a force close of the application (i start another activity) I suppose it's because of that problem.

我不知道问题是什么因为我不要手动处理任何XML文件,我的WDSL很好,你可以看到 这里

I have no idea what's the problem much because I don't handle any XML file manually and my WDSL is fine as you can see 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;
    }

我真的不知道为什么会发生这种情况....任何帮助?

I honestly have no idea why this happens.... any help?

发现问题(但不是解决方案......)

我倾销响应xml文件,看起来像它的商城形成:

I dumped the response xml file, and looks like it's mall formed:

<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>
<!..................

信封本身没关系,但没有结束评论标签......我怎么能解决这个问题?

The envelope itself it's ok, but there is not ending comment tag... how can I solve this ?

推荐答案

看起来这是关于api级别的KSOAP2 android实现的问题< 9。

Looks like it's an issue on KSOAP2 android implementation on api level < 9.

使用

System.setProperty("http.keepAlive", "false");

我希望有人希望有人,因为我看到有数十人遇到同样的问题。

I hope this hopes someone, because I saw dozens of people with the same problem.

这篇关于使用KSOAP2连接到Web服务 - 获取XmlPullParserException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆