HttpURLConnection disconnect doesn't work in Android -
the method disconnect httpurlconnection
seems not work properly. if execute following code:
url = new url("http:// ..."); connection = (httpurlconnection) url.openconnection (); connection.setrequestmethod("post"); connection.setrequestproperty("content-type", "application/x-www-form-urlencoded"); connection.setusecaches(false); connection.setdoinput(true); connection.setdooutput(true); connection.connect(); // code connection.disconnect(); connection.setdoinput(false); // -> illegalstateexception
i illegalstateexception
when call method setdoinput
. exception says:
already connected
it sounds you're trying reuse connection? i.e. altering request properties after you've disconnected server, ready make connection.
if case, create new httpurlconnection
object.
Comments
Post a Comment