Exception; Cannot set request property after connection is made; occurs on Android lollipop HTC M8

杀马特。学长 韩版系。学妹 提交于 2019-12-10 15:17:03

问题


I am calling a Java Web Service from an Androidapplication using Soaprequests. There is a certain method to be called through the app which works fine in Android versions up to Kit Kat in almost all the devices and in Samsung Lollipop devices too, but doesn't work on HTC M8 Lollipop updated device.
Following 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();
}

An Exception occurs when trying to get the response as indicated by the comment and the exact Exception is 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 have been searching for this but could not find a proper answer or a workaround even.

I looked for
Ksoap2 Android IllegalStateException
and
setRequestProperty method giving java.lang.IllegalStateException: Cannot set method after connection is made

I have no idea why it is occured in HTC M8 Lollipop device but not in Samsung Lollipop devices.
Any suggestions or workarounds are much appreciated.
Thank you


回答1:


I think this might explain the issue. 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..

You can do two possible things to identify exactly if this is the issue.

  1. Try renaming the ksoap2 class name
  2. Directly access ksoap2 class with preceding the package name.


来源:https://stackoverflow.com/questions/29765186/exception-cannot-set-request-property-after-connection-is-made-occurs-on-andro

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