title: Android - Can we still get content by HttpURLConnection if server's response code is 404
body: <p>I have an simple Android code to call api from a link:</p>
  
  <pre><code>class RetrieveDataTask extends AsyncTask&lt;Void, Void, String&gt; {
  
          private Exception exception;
  
          protected void onPreExecute() {
              progressBar.setVisibility(View.VISIBLE);
              responseView.setText("");
          }
  
          protected String doInBackground(Void... urls) {
              String email = linkText.getText().toString();
              // Get url from the Edittext
  
              try {
                  URL url = new URL(linkText.getText().toString());
                  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                  statusCode = urlConnection.getResponseCode();
                  Log.d("RESPONSE_CODE", "doInBackground: " + statusCode);
                  try {
                      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                      StringBuilder stringBuilder = new StringBuilder();
                      String line;
                      while ((line = bufferedReader.readLine()) != null) {
                          stringBuilder.append(line).append("\n");
                      }
                      bufferedReader.close();
                      return stringBuilder.toString();
                  }
                  finally{
                      urlConnection.disconnect();
                  }
              }
              catch(Exception e) {
                  Log.e("ERROR", e.getMessage(), e);
                  return null;
              }
          }
  
          protected void onPostExecute(String response) {
              if(response == null) {
                  response = "THERE WAS AN ERROR";
              }
              progressBar.setVisibility(View.GONE);
              Log.i("INFO", response);
              responseView.setText(response);
          }
      }
  </code></pre>
  
  <p>For some sort of api link (please forgive me I cannot provide it), the JSON shows <em>beautifully</em> on browser, but in Logcat (the "Log.d" command above), the status shows 404 (which means Not Found !).
  This leads me to a question about writing a client app that request data from server. Can a client app still get the data if the server repond with code 404 or 400 (Bad Request) or something <strong>when the data still shows well on brower</strong> ?</p>
  
  <p>Update: I also saw some strange behaviour when calling an API. For example on this link:</p>
  
  <pre><code>https://jsonplaceholder.typicode.com/photos
  </code></pre>
  
  <p>The response on browser shows well, but the result shows on my emulator is like this:
  <a href="https://i.stack.imgur.com/omA3S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/omA3S.png" alt="enter image description here"></a></p>
  
  <p>I'm getting crazy now !</p>