较新的手机不支持宽带连接

时间:2012-10-16 08:01:17

标签: android sockets ksoap

所以我试图使用kso​​ap从webservice收集一些数据。它适用于较旧的手机,并且当我有wifi连接时更新。当我从移动服务提供商更改为宽带时,它会返回错误:

 java.net.SocketException: Socket is closed

有人知道为什么会这样吗?真的很奇怪我有两部手机都连接到同一个网络服务,既使用了相应的应用程序,又使用了较旧的手机,而新手机则没有。

顺便说一下我的代码:

String METHOD_NAME = "MPList";
String SOAP_ACTION = "https://server.location:443/MobileWS/#MPList";
String NAMESPACE = "https://server.location:443/MobileWS/";
String URL = "https://server.location:443/MobileWS/";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("user", user);
request.addProperty("pass", pass);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();

headerList.add(new HeaderProperty("Content-Type", "text/xml; charset=utf-8"));
headerList.add(new HeaderProperty("SoapAction", "https://server.location/#MPList"));
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);  
httpTransport.debug = true;
try{
    httpTransport.call(SOAP_ACTION, envelope, headerList);
    SoapObject response = (SoapObject)envelope.bodyIn;
    String a=httpTransport.responseDump;
} catch (IOException e2) {
    e2.printStackTrace();
} catch (XmlPullParserException e2) {
    e2.printStackTrace();
}

1 个答案:

答案 0 :(得分:0)

好像Android 4.0.3和4.0.4中存在问题,所以它不适用于https。链接:http://code.google.com/p/android/issues/detail?id=29509&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

如果有人再次遇到这个问题,这就是解决方案:

你必须添加http“Connection”属性和“keep-alive”值。

 headerList.add(new HeaderProperty("Connection", "keep-alive"));

这解决了我的问题!!!