title: Consume REST web service in android
body: <p>I'm tyring to consume a REST Web Service which returns a JSON Dictionary but the app crashes when I  call   </p>
  
  <pre><code>HttpResponse resp = httpClient.execute(post);
  </code></pre>
  
  <p>This is my code:    </p>
  
  <pre><code>System.out.println("onClick!!!");
          HttpClient httpClient = new DefaultHttpClient();
          HttpPost post = new HttpPost("http://applocalize.com.br/rest/rest.php");
          post.setHeader("content-type", "application/json; charset=UTF-8");
          post.setHeader("Accept", "application/json");
          //Construimos el objeto cliente en formato JSON
          JSONObject dato = new JSONObject();
  
          try {
              dato.put("pg","categorias");
              dato.put("serv", "buscar");
              dato.put("dt_atualizacao", "");
  
              StringEntity entity = new StringEntity(dato.toString());
              post.setEntity(entity);
  
              HttpResponse resp = httpClient.execute(post);
              String respStr = EntityUtils.toString(resp.getEntity());
  
  
              System.out.println("OKAY!");
  
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>LOGCAT:</p>
  
  <pre><code> 28517-28517/com.allapps.localizeapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.allapps.localizeapp/com.allapps.localizeapp.MapsActivity}: android.os.NetworkOnMainThreadException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2252)
              at 
  </code></pre>