title: Exception on httpclient.execute to web server
body: <p>I try to send JSON data on web server and get response by this method.</p>
  
  <pre><code>public JSONObject postOnServer(JSONObject json) {
  
      HttpResponse response;
      JSONObject res = null;
  
      HttpClient httpclient = new DefaultHttpClient();
      HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 10000);
      HttpPost httpPost = new HttpPost(PATH);
  
      try {
  
          //StringEntity stringEntity = new StringEntity("json", String.valueOf(json));
          ByteArrayEntity postMessage = new ByteArrayEntity(json.toString().getBytes("UTF8"));
          httpPost.setEntity(postMessage);
          response = httpclient.execute(httpPost);
  
          if (response.getStatusLine().getStatusCode() == 200) {
  
              InputStream instream = response.getEntity().getContent();
              try {
                  res = new JSONObject(convertStreamToString(instream));
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  Log.i("Response JSON", e.toString());
              }
  
          } else {
  
              res = new JSONObject();
              try {
                  res.put("error", "Unable to load page.");
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
              }
  
          }
      } catch (IOException ex) {
  
          Log.i("Connection.postOnServer", "1.try exception: "+ex);
          res = new JSONObject();
          try {
              res.put("error", "Synchronization is not enable: Connection has aborted.");
          } catch (JSONException e) {
              Log.i("Connection.postOnServer", "put exception: "+e);
          }
  
      }
  
      return res;
  }
  </code></pre>
  
  <p>But always it end on line <code>response = httpclient.execute(httpPost);</code> with this exception</p>
  
  <pre><code>05-24 10:58:51.635: E/AndroidRuntime(4709): FATAL EXCEPTION: main
  05-24 10:58:51.635: E/AndroidRuntime(4709): android.os.NetworkOnMainThreadException
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at libcore.io.IoBridge.connectErrno(IoBridge.java:138)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at libcore.io.IoBridge.connect(IoBridge.java:112)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at java.net.Socket.connect(Socket.java:842)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  05-24 10:58:51.635: E/AndroidRuntime(4709):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  </code></pre>
  
  <p>Have someone idea, how to fix it? On thirst try if i use catch(IOException), aplication is destroyd. If I use catch(Exception) aplication go on with no action. What should I do to send data?</p>