java.io.EOFException using ksoap2 lib libcore.io.Streams.readAsciiLine(Streams.java:203)

谁说胖子不能爱 提交于 2019-12-08 01:59:30

问题


03-26 14:12:19.045: E/Webservices(2863): java.io.EOFException
03-26 14:12:19.045: E/Webservices(2863):    at libcore.io.Streams.readAsciiLine(Streams.java:203)
03-26 14:12:19.045: E/Webservices(2863):    at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
03-26 14:12:19.045: E/Webservices(2863):    at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
03-26 14:12:19.045: E/Webservices(2863):    at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
03-26 14:12:19.045: E/Webservices(2863):    at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
03-26 14:12:19.045: E/Webservices(2863):    at org.ksoap2.transport.ServiceConnectionSE.getResponseCode(ServiceConnectionSE.java:103)
03-26 14:12:19.045: E/Webservices(2863):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:197)
03-26 14:12:19.045: E/Webservices(2863):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
03-26 14:12:19.045: E/Webservices(2863):    at .utils.Webservices.callinternet(Webservices.java:125)
03-26 14:12:19.045: E/Webservices(2863):    at .utils.Webservices.getResponse(Webservices.java:73)
03-26 14:12:19.045: E/Webservices(2863):    at .utils.Webservices.getResponse(Webservices.java:79)
03-26 14:12:19.045: E/Webservices(2863):    at .utils.Webservices.getResponse(Webservices.java:79)
03-26 14:12:19.045: E/Webservices(2863):    at .utils.AsynTask.doInBackground(AsynTask.java:61)
03-26 14:12:19.045: E/Webservices(2863):    at .utils.AsynTask.doInBackground(AsynTask.java:1)
03-26 14:12:19.045: E/Webservices(2863):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-26 14:12:19.045: E/Webservices(2863):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-26 14:12:19.045: E/Webservices(2863):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-26 14:12:19.045: E/Webservices(2863):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-26 14:12:19.045: E/Webservices(2863):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-26 14:12:19.045: E/Webservices(2863):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-26 14:12:19.045: E/Webservices(2863):    at java.lang.Thread.run(Thread.java:856)

When i call the webservice from android this exception come some time only how can be clear this please help me

i atteded

ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
    headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));

this line also but no use


回答1:


This is a bug, I am getting the same error while using ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar. It looks like this problem has been prevailing since v3.1.1 (some users faced this in earlier releases too). A user with gave a workaround to tackle this problem. According to him,

ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));
httpSE.call(SOAP_ACTION, envelope, headerPropertyArrayList);

did the trick. I tried it and it worked for me. If you are still facing the problem then you can use ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar. I am using this version on another project of mine and it has never given me any problems.




回答2:


I got the same error, but I solved it out, actually soap webservice operation(method) name was misspelled that's why java.io.EOFException Exception was thrown by Ksoap2 library So check your operation(method) name, namespace name and soapAction(name space/method name). I think this will help you to handle this exception




回答3:


Hi I have faced the same issue.Please use connection time out parameter to avoid this exception.

HttpTransportSE androidHttpTransport = new HttpTransportSE("Your Url here",120000);

and also set connection close parameter in header.

ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));
httpSE.call(SOAP_ACTION, envelope, headerPropertyArrayList);



回答4:


EOFException - Signals that an end of file or end of stream has been reached unexpectedly during input. This exception is mainly used by data input streams to signal end of stream. Note that many other input operations return a special value on end of stream rather than throwing an exception.

So: after call() your HttpTransportSE instance do instance.getServiceConnection().openOutputStream().close();

MyCode:

HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
try {
    androidHttpTransport.call(mSoapAction, envelope);            
    response = (SoapObject) envelope.bodyIn;

    androidHttpTransport.getServiceConnection().openOutputStream().close();
} catch (IOException | XmlPullParserException e) {
    e.printStackTrace();           
}


来源:https://stackoverflow.com/questions/22680533/java-io-eofexception-using-ksoap2-lib-libcore-io-streams-readasciilinestreams-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!