title: Can you explain the HttpURLConnection connection process?
body: <p>I am using <code>HTTPURLConnection</code> to connect to a web service. I know how to use <code>HTTPURLConnection</code> but I want to understand how it works. Basically, I want to know the following:</p>
  
  <ul>
  <li>On which point does <code>HTTPURLConnection</code> try to establish a connection to the given URL?</li>
  <li>On which point can I know that I was able to successfully establish a connection?</li>
  <li>Are establishing a connection and sending the actual request done in one step/method call? What method is it?</li>
  <li>Can you explain the function of <code>getOutputStream</code> and <code>getInputStream</code> in layman's term? I notice that when the server I'm trying to connect to is down, I get an <code>Exception</code> at <code>getOutputStream</code>. Does it mean that <code>HTTPURLConnection</code> will only start to establish a connection when I invoke <code>getOutputStream</code>? How about the <code>getInputStream</code>? Since I'm only able to get the response at <code>getInputStream</code>, then does it mean that I didn't send any request at <code>getOutputStream</code> yet but simply establishes a connection? Do <code>HttpURLConnection</code> go back to the server to request for response when I invoke <code>getInputStream</code>?</li>
  <li>Am I correct to say that <code>openConnection</code> simply creates a new connection object but does not establish any connection yet?</li>
  <li>How can I measure the read overhead and connect overhead?</li>
  </ul>