title: HttpURLConnection differences in android 2.3.x and 4.0.3
body: <p>Here's a description of what I'm trying to do:
  I want to send a login form to a website through HttpURLConnection.
  So first of all I'm sending a GET request to the login page, to check that it exist and that I'm not already logged in.
  After I'm closing the connection and the input stream, I'm making the parameters to send.
  Then I'm making a POST request to actually log in.</p>
  
  <p>The code:</p>
  
  <pre><code>url = new URL("http://www.example.com/login/");
  con = (HttpURLConnection) url.openConnection();
  in = con.getInputStream();
  if(con.getResponseCode()==HttpURLConnection.HTTP_OK){
      loginData = getResponseData(in); // InputStream to String
      in.close();
      if(isBlank(loginData)){
          return StatusCode.CONNECTION_FAILED; // no login page
      }
      if (Login.getLoginStatus(loginData)) {
          return StatusCode.NO_ERROR; // already logged in
      }
  }
  con.disconnect();
  
  String params = "password="+URLEncoder.encode(login.second,"UTF-8")+
          "&amp;username="+URLEncoder.encode(login.first,"UTF-8");
  
  url = new URL("http://www.example.com/login/login.php");
  con = (HttpURLConnection) url.openConnection();
  con.setDoOutput(true);
  con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  con.setFixedLengthStreamingMode(params.getBytes().length);
  out = con.getOutputStream();
  out.write(params.getBytes());
  out.close();
  in = con.getInputStream(); \\ THIS IS WHERE IT GETS STUCK
  if(con.getResponseCode()==HttpURLConnection.HTTP_OK){
      loginData = getResponseData(in);
      in.close();
      if(isBlank(loginData)){
          return StatusCode.CONNECTION_FAILED; // no login page
      }
      if (Login.getLoginStatus(loginData)) {
          return StatusCode.NO_ERROR; // logged in
      }   
      if (loginData.contains("Invalid username and//or password.")) {
          return StatusCode.WRONG_LOGIN_DATA; // wrong login
      }
  }
  con.disconnect();
  </code></pre>
  
  <p>In version 2.3.x it returns response code: 302, no data in the InputStream (the <code>con.getInputStream()</code> is very quick), and I can see all the headers in eclipse debug mode.</p>
  
  <p>In version 4.0.3 it returns response code: 200, all the data in the InputStream (the <code>con.getInputStream()</code> is getting stuck for about 2 minutes), and in debug mode I can read the following:</p>
  
  <pre><code>con.ResponseCode = -1
  con.ResponseMessage = null
  con.redirectionCount = 1
  </code></pre>
  
  <p>Do you know why is the differences, and how I can manage to get it work in every version from 2.3.x and above?</p>