title: HttpURLConnection GET request on Android gives weird 501 code
body: <p>I have a weird issue when using <code>HttpURLConnection</code> on android it gives me a status code 501 but when I try the request on curl, it gives me status code 200.</p>
  
  <pre><code>curl -X GET \
  -H "Accept-Charset: UTF-8" \
  https://domain.com/v1/resource?token=token12345
  </code></pre>
  
  <p>This is my <code>HttpURLConnection</code> <code>GET</code> request snippet</p>
  
  <pre><code>public MyResponse get(String params) {
      HttpURLConnection connection = null;
      InputStreamReader inputStream = null;
      BufferedReader reader = null;
      MyResponse response = null;
  
      String tokenParam = "?token=" + params;
  
      try {
          URL url = new URL(BASE_URL + API_VER + mResource + tokenParam);
          connection = (HttpURLConnection) url.openConnection();
          connection.setRequestMethod(Method.GET);
          connection.setRequestProperty(Header.ACCEPT_CHARSET, Value.UTF_8);
          connection.setDoInput(true);
          connection.setDoOutput(true);
          connection.connect();
  
          int statusCode = connection.getResponseCode(); // code 501
  
          inputStream = new InputStreamReader(connection.getInputStream());
          reader = new BufferedReader(inputStream);
          StringBuilder message = new StringBuilder();
          String line;
          while ((line = reader.readLine()) != null) {
              message.append(line);
          }
  
          response = new MyResponse();
          response.setMessageBody(message.toString());
          response.setStatusCode(statusCode);
          if (statusCode == HTTP_OK || statusCode == HTTP_CREATED) {
              response.setSuccess(true);
          } else {
              response.setSuccess(false);
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      } finally {
          if (connection != null) connection.disconnect();
          try {
              if (inputStream != null) inputStream.close();
              if (reader != null) reader.close();
  
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      return response;
  }
  </code></pre>
  
  <p>Am I missing anything?</p>