Android AsyncTask and HTTP post - Works only one time? -


i have asynctask in application creates httpurlconnection. next, calls getoutputstream(), writes bytes, flushes , closes. calls getresponsecode(), , getinputstream(). if need post code, can, thought i'd keep question small.

when run first time, 200 response code, , correct input stream.

when run second fifth time, new thread (viewable in ddms view), , receive 500 response code, , ioexception when getting input stream.

when call sixth time or more, no new threads created, , still 500 response code , ioexception.

what can here? works 1 time , never again. has else seen this? i'm stumped.

here's minimal code (i removed try/catch, variable declarations, app specific stuff, etc):

   protected string doinbackground(string... params)    {      connecturl = new url(swebpath);      conn = (httpurlconnection)connecturl.openconnection();       conn.setdoinput(true);      conn.setdooutput(true);      conn.setusecaches(false);      conn.setconnecttimeout(10000);       conn.setrequestmethod("post");       conn.setrequestproperty("user-agent", "myappagent");      conn.setrequestproperty("connection", "keep-alive");      conn.setrequestproperty("content-type", "application/soap+xml; charset=utf-8");       // setup post string s.       conn.setrequestproperty("content-length", string.valueof(s.length()));       conn.connect();      dataoutputstream datastream = new dataoutputstream(conn.getoutputstream());      datastream.writebytes(s);       datastream.flush();      datastream.close();      datastream = null;       // 200 1st time only, 500 after that.      responsecode = conn.getresponsecode();       // works 1st time only, io error after      datainputstream dis = new datainputstream(conn.getinputstream());      byte[] data = new byte[16384];      int len = dis.read(data, 0, 16384);       dis.close();      conn.disconnect();       response = new string(data, 0, len);       // whatever response   }    @override   protected void onpostexecute(string result)   {      super.onpostexecute(result);       // call toast message on original context used       // create asynctask.   }     // onclicklistener of button calls asynctask (tierrequest class) 2 lines   tierrequest t = new tierrequest(whatevermycurrentactivityis.this);   t.execute(a_constant_indicating_the_type_of_post); 

this feels problem on server (code 500 universally used indicate sort of problem in server side code, although problem web server itself).

do control server code? possibly opening file , not closing it, additional calls may run "access denied" or "file open" errors?


Comments