title: android SocketException: Socket closed
body: <p>i am executing post request to apache server with DefaultHttpClient.
  I am trying to get the response.
  When the response is like 100 symbols is working fine, byt when i have biger response like 300 symbols i have socket exeption:socket close.</p>
  
  <p><strong>the exceptions</strong> :</p>
  
  <pre><code>12-14 11:23:26.905: W/System.err(10082): java.net.SocketException: Socket closed
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.harmony.luni.platform.OSNetworkSystem.read(Native Method)
  12-14 11:23:26.905: W/System.err(10082):    at dalvik.system.BlockGuard$WrappedNetworkSystem.read(BlockGuard.java:273)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:458)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:174)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:188)
  12-14 11:23:26.905: W/System.err(10082):    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:178)
  12-14 11:23:26.913: W/System.err(10082):    at com.androidhive.pushnotifications.JSONParser.getJSONFromUrl(JSONParser.java:174)
  12-14 11:23:26.913: W/System.err(10082):    at com.androidhive.pushnotifications.JSONParser.doInBackground(JSONParser.java:233)
  12-14 11:23:26.913: W/System.err(10082):    at com.androidhive.pushnotifications.JSONParser.doInBackground(JSONParser.java:1)
  12-14 11:23:26.913: W/System.err(10082):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
  12-14 11:23:26.913: W/System.err(10082):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  12-14 11:23:26.913: W/System.err(10082):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  12-14 11:23:26.921: W/System.err(10082):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  12-14 11:23:26.921: W/System.err(10082):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  12-14 11:23:26.921: W/System.err(10082):    at java.lang.Thread.run(Thread.java:1019)
  </code></pre>
  
  <p><strong>My code</strong> :</p>
  
  <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(url);
          HttpResponse getResponse= null;
  
  
  
          if(json_post!=null){
              StringEntity se=null;
              try {
                  se = new StringEntity(json_post.toString());
              } catch (UnsupportedEncodingException e3) {
                  // TODO Auto-generated catch block
                  e3.printStackTrace();
              }
              //sets the post request as the resulting string
              httpPost.setEntity(se);
          }
          HttpProtocolParams.setUserAgent(httpClient.getParams(), "Mozilla/5.0");try {
              getResponse = httpClient.execute(httpPost);
  
          } catch (ClientProtocolException e2) {
              statusCode = "ClientProtocolException";
              e2.printStackTrace();
          } catch (IOException e2) {
              statusCode = "IOException";
              e2.printStackTrace();
          } finally {
              httpClient.getConnectionManager().shutdown(); // Close the instance here
          }
  
  
  
          if (getResponse == null) return null;
          statusCode = ""+getResponse.getStatusLine().getStatusCode();
          if (!statusCode.equals( ""+HttpStatus.SC_OK) ) { 
             Log.w(getClass().getSimpleName(), 
                "Error " + statusCode + " for URL " + url); 
  
             return null;
          }
  
  
          HttpEntity getResponseEntity = getResponse.getEntity();
  
          InputStream inputStream = null;
          try {
              inputStream = getResponseEntity.getContent();
          } catch (IllegalStateException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
  
          ByteArrayOutputStream content = new ByteArrayOutputStream();
  
          // Read response into a buffered stream
          int readBytes = 0;
          byte[] sBuffer = new byte[512];
          try {
              while ((readBytes = inputStream.read(sBuffer)) != -1) {
                  content.write(sBuffer, 0, readBytes);
              }
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
  
          // Return result from buffered stream
          String dataAsString = new String(content.toByteArray());
  </code></pre>
  
  <p>please help :)</p>