Hi guys.
I am facing with problem related Http Connection. MY code :
URL url = null;
try {
url = new URL(_url);
} catch (MalformedURLException e) {
}
if (url != null) {
HttpURLConnection urlConn = null;
InputStreamReader isr = null;
try {
urlConn = (HttpURLConnection)url.openConnection();
urlConn.setRequestMethod("GET");
urlConn.setConnectTimeout(45000);
if(response == HttpURLConnection.HTTP_OK) {
StringBuffer readData = new StringBuffer("");
int size = 1024;
char[] buffer = new char[size];
int len;
isr = new InputStreamReader(urlConn.getInputStream());
while ((len = isr.read(buffer, 0, size)) > 0) {
readData.append(buffer, 0, len);
}
}
}
catch(Exception e) {
}
finally {
if(urlConn != null) {
try {
urlConn.disconnect();
} catch(Exception e) {
}
}
if(isr != null) {
try {
isr.close();
} catch(Exception e) {
}
}
}
This code can't download data completely. For example : Total size to read : 13901 bytes Above code can read size : 12937 bytes
What is wrong here ?
Please advice guys.