title: HttpsURLConnection and intermittent connections
body: <p>I'm hoping someone could help me out with intermittent connections I'm 
  getting using code with HttpsURLConnection. The code I'm using is 
  below: </p>
  
  <pre><code>HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
              conn.setReadTimeout(10 * 1000); 
  if conn.getResponseCode() != 200) { 
              Log.v(TAG, "error code:" + conn.getResponseCode()); 
  } 
  </code></pre>
  
  <p>The connection works the first time everytime when I use it to pull a 
  json file. However, when I use the connection again to send a command, 
  it always fails the first time. It then typically works if I send the 
  command quickly ( within 5 seconds), but fails if I wait a while. 
  I don't think its a SSL issue because it connects the first time 
  correctly, but I could be wrong here. I also tried many different 
  variations such as adding: </p>
  
  <pre><code>conn.setUseCaches(false); 
  conn.setRequestProperty("Connection","Keep-Alive"); 
  conn.getHostnameVerifier(); 
  conn.getSSLSocketFactory(); 
  conn.setDoOutput(true); 
  conn.setDoInput(true); 
  conn.setRequestMethod("POST"); 
  conn.wait(100); 
  </code></pre>
  
  <p>However, I had no luck. Any help would be greatly appreciated. </p>