tags:

views:

28

answers:

0

I am using HttpUrlConnetion to post data to server and read data from server.

I am able to send compressed data to server and server sending again compressed data to client, but while reading data from server, android application is reading approximately 50% data not full data. Would any one suggest how to overcome this? is there any buffer size?

 public void sendRequest(String compressData, String id)
   throws InterruptedException {
  try {
   URL url = new URL(SERVER_URL);
   hCon = (HttpURLConnection) url.openConnection();

   hCon.setDoOutput(true);
   hCon.setDoInput(true);

   hCon.setRequestMethod("POST");
   hCon.setRequestProperty("Content-Type",
     "application/x-www-form-urlencoded");

   hCon.connect();

   // write data to server
   OutputStream dos = hCon.getOutputStream();
   String str = xmlStanza(compressData, id);
   // Log.e("To serverer", str);
   dos.write(str.getBytes("UTF-8"));
   dos.flush();
   dos.close();

   // read data from server
   InputStream dis = hCon.getInputStream();
   Log.e("Cahar set", "" + dis.available());
   BufferedReader br = new BufferedReader(new InputStreamReader(dis,
     Charset.forName("UTF-8")));

   StringBuffer sb = new StringBuffer();
   // int ch;
   // while ((ch = dis.read()) != -1) {
   // sb.append((char) ch);
   // }
   str = "";
   while ((str = br.readLine()) != null) {
    sb.append(str);
   }
   Log.e("From serverer", "" + sb.toString());
   // parse(dis);
   // parse(sb.toString());
   br.close();
   dis.close();

  } catch (IOException ex) {

   Log.e("Exception", ex.getMessage());

  } finally {
   hCon.disconnect();
   hCon = null;
  }
 }

Need help..