title: HttpURLConnection.getInputStream() hangs and never finishes
body: <p>I am attempting to get a token from a JSON endpoint using the following code:</p>
  
  <pre><code>public class FetchToken extends AsyncTask&lt;String, Void, Void&gt; {
      String data = "";
      String token = "";
  
      public TokenDelegate delegate = null;
  
      @Override
      protected Void doInBackground(String... identity) {
          try {
              if (identity.length == 1) {
                  URL url = new URL(identity[0]);
  
                  HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                  InputStream inputStream = httpURLConnection.getInputStream();
                  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                  String line = "";
  
                  while (line != null) {
                      line = bufferedReader.readLine();
                      data = data + line;
                  }
  
                  JSONObject JO = new JSONObject(data);
                  token = JO.get("token").toString();
              }
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return null;
      }
  
      @Override
      protected void onPostExecute(Void aVoid) {
          Log.d("token", token);
          //delegate.processFinish(token);
          super.onPostExecute(aVoid);
      }
  }
  </code></pre>
  
  <p>I have tried printing to the debug log after every line, and it seems that the line <code>InputStream inputStream = httpURLConnection.getInputStream();</code> never finishes, nor does the rest of the code get executed. However, this is taking place inside of an AsyncTask, and the onPostExecute method of that AsyncTask is firing as if the task has been completed, which it doesn't seem as if it has been.</p>
  
  <p>None of the catch blocks are being executed, it seems like, and when I inspect the Network panel in the Android Profiler then the request says it is not passing anything back. However, accessing the JSON endpoint in browser brings everything back correctly.</p>
  
  <p>Hopefully someone knows what the problem may be. I've attempted to google things to no avail. Let me know if more information is needed. Thanks.</p>