title: HttpUrlConnection must be declared every time?
body: <h1>1</h1>
  
  <pre><code>for(int i=0; i&lt;3; i++)
      {
          URL url = new URL("http://localhost/network_test.php");
          HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  
          DataOutputStream wr = new DataOutputStream(
                  connection.getOutputStream ());
          wr.writeBytes("some data to send");
          wr.flush();
          wr.close();
  
          // prepare request to server
  
          // ...
  
          // recive data from server
  
          connection.disconnect();
      }
  </code></pre>
  
  <h1>2</h1>
  
  <pre><code>URL url = new URL("http://localhost/network_test.php");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  
  for(int i=0; i&lt;3; i++)
      {
          DataOutputStream wr = new DataOutputStream(
                  connection.getOutputStream ());
          wr.writeBytes("some data to send");
          wr.flush();
          wr.close();
  
  
          // prepare request to server
  
          // ...
  
          // recive data from server
      }
  
  connection.disconnect();
  </code></pre>
  
  <p>First options work perfect!</p>
  
  <p>But why i can't use #2 version? Every time I must create new object HttpUrlConnection? Why?</p>
  
  <p>Error at #2 version:</p>
  
  <blockquote>
    <p>java.net.ProtocolException: cannot write request body after response has been read</p>
  </blockquote>