exception; Request properties cannot be set after the connection is established; Happens on Android Lollipop HTC M8
I’m using Soap
a request to call Java Web 服务
from Android
an application. There is a specific method that can be called through the app, and it works fine on almost all devices and versions of Android
Samsung Lollipop
until Kit Kat
> devices as well, but not for HTC M8 Lollipop update devices.
Below is my code.
HttpTransportSE ht = new HttpTransportSE("URL");
SoapObject so = new SoapObject("Namespace", "Method");
try {
SoapSerializationEnvelope se = new SoapSerializationEnvelope(SoapEnvelope.VER11);
so.addProperty("input1", data);
data = se.getResponse().toString();//This is where Exception occurs
}catch(Exception ex){
ex.printStackTrace();
}
OccursException
when trying to get the response indicated by the comment, exactlyException
as follows.
java.lang.IllegalStateException: Cannot set request property after connection is made
at com.android.okhttp.internal.http.HttpURLConnectionImpl.setRequestProperty(HttpURLConnectionImpl.java:496)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.setRequestProperty(DelegatingHttpsURLConnection.java:258)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:25)
at org.ksoap2.transport.ServiceConnectionSE.setRequestProperty(ServiceConnectionSE.java:101)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:156)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
I’ve been looking for this but can’t find a suitable answer or workaround.
I looked for it
Ksoap2 Android IllegalStateException
and
setRequestProperty method giving java.lang.IllegalStateException: Cannot set method after connection is made
I don’t know why it appears in HTC M8 Lollipop
devices, but not in Samsung Lollipop
devices.
Any suggestions or workarounds are greatly appreciated.
Thank you
Solution
I think this would explain the problem. Look for the 4th particle in the thread.
https://code.google.com/p/ksoap2-android/issues/detail?id=205&can=1&start=200
It says,
Ahh.. they might have added ksoap2 android in their firmware.. that
would explain it. Not sure that is anything you can do beyond shading
the whole ksoap2-android package you use and any dependencies into
your own namespace. A rather huge undertaking..
There are two things you can do to determine exactly if this is the problem.
- Try renaming
ksoap2
Class Name 包
Accessksoap2
the class directly before the name.