I am using apache httpclient, which comes with sdk for Android, to upload the file to the server using a multi-page HTTP message. The problem is that when I turn off the wifi connection on my device and the device does not have Internet access and events after setting the sotimeout timeout and connection time, the code hangs in the httpclient.execute() statement indefinitely, and this happens every time.
my code is:
HttpClient httpclient = new DefaultHttpClient(); HttpConnectionParams.setSoTimeout(httpclient.getParams(), 5000); ConnManagerParams.setTimeout( httpclient.getParams(), 5000 ); HttpConnectionParams.setSocketBufferSize(httpclient.getParams(), 8192); HttpPost("http://myurl"); File file = new File(fileAbsolutePath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file); mpEntity.addPart("uploadedfile", cbFile); httppost.setEntity(mpEntity); if(!backupCancel) { System.out.println("<<<<<<<<<<<<<<<<<<<<<<Actually transferring file>>>>>>>>>>>>>>>"); HttpResponse response = httpclient.execute(httppost); }
Nitin source share