title: How to use HttpURLConnection with Response (Content-Type: text/html ) in android?
body: <p>My qustion is about the code that should be written in Android using HttpURLConnection to get the response?</p>
  
  <p>The Request and 2 Response as following:</p>
  
  <p>Request
  [Headers
  Authorization: ******]</p>
  
  <p>Response<br>
  [code: 302,
  Headers
  (Content-Type: text/html)]</p>
  
  <p>Response<br>
  [code: 302,
  Headers
  (Content-Type: text/html)]</p>
  
  <p>The code:</p>
  
  <p>private void makeHttpRequest(URL url) throws IOException {</p>
  
  <pre><code>    String redirectUrl;
  
      HttpURLConnection urlConnection = null;
      try {
          urlConnection = (HttpURLConnection) url.openConnection();
          urlConnection.setRequestMethod("GET");
          urlConnection.setReadTimeout(10000 /* milliseconds */);
          urlConnection.setConnectTimeout(15000 /* milliseconds */);
          urlConnection.addRequestProperty("Authorization", "********");
          urlConnection.connect();
  
          if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK
                  || urlConnection.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM
                  || urlConnection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) {
  
              redirectUrl = urlConnection.getHeaderField("Content-Type");
  
          } else {
              Log.e(LOG_TAG, "Error redirect response code: " + urlConnection.getResponseCode());
          }
  
      } catch (IOException e) {
          Log.e(LOG_TAG, "Problem retrieving", e);
      } finally {
          if (urlConnection != null) {
              urlConnection.disconnect();
          }
      }
  }
  </code></pre>