title: Right way to manage HTTP connection in Android
body: <p>I have written two programs which handle the HTTP request. I wanted to know if one is better than other -</p>
  
  <p>Program 1 (Using HttpURLConnection)</p>
  
  <pre><code>          URL url = new URL("https://www.google.com/");
  
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  
            connection.setRequestMethod("GET");
  
            connection.setDoOutput(false);
  
            connection.connect();
  
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  
            stringBuilder = new StringBuilder();
  </code></pre>
  
  <p>Program 2 (Using HttpPost)</p>
  
  <pre><code>         DefaultHttpClient httpClient = new DefaultHttpClient();
  
           HttpPost httpPost = new HttpPost("https://test.com");
  
           HttpResponse httpResponse = httpClient.execute(httpPost);
  
           InputStream inputStream = httpResponse.getEntity().getContent();
  
           InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
  </code></pre>
  
  <p>Also in program 2, I use a singleton to get the connection object. But in program 1 there is no global connection object and I need to recreate the HttpURLConnection object everytime I make a request. Please let me know if I am on the right track.</p>
  
  <p>Thank You</p>