title: android.os.NetworkOnMainThreadException for android app
body: <p>I am trying to call a url which has json data.</p>
  
  <pre><code>String response = null;
      try {
          URL url = new URL("https://demorul.com");
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setReadTimeout(10000);
          conn.setConnectTimeout(10000);
          conn.setRequestMethod("GET");
          conn.setRequestProperty("Content-Type", "application/json;odata=verbose");
          conn.setRequestProperty("Accept", "application/json;odata=verbose");
  
          // read the response
          InputStream in = new BufferedInputStream(conn.getInputStream());
          response = convertStreamToString(in);
      } catch (MalformedURLException e) {
          Log.e(TAG, "MalformedURLException: " + e.getMessage());
      } catch (ProtocolException e) {
          Log.e(TAG, "ProtocolException: " + e.getMessage());
      } catch (IOException e) {
          Log.e(TAG, "IOException: " + e.getMessage());
      } catch (Exception e) {
          Log.e(TAG, "Exception: " + e.getMessage());
      }
      return response;
  </code></pre>
  
  <p>The url will return json data. But i am getting android.os.NetworkOnMainThreadException error mean its goes to last catch statement. </p>
  
  <p>In AndroidManifest.xml file i have set</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  </code></pre>
  
  <p>Thanks</p>