java http Url connection for multiple post requests
<p>I need help regarding the persistent httpurlconnection</p>

<p>my method header looks like</p>

<p>public boolean sendToAPI(ArrayList logs)
{</p>

<p>} </p>

<p>i need to be able to open the HttpUrlConnection and call multiple post request by iterating through the log list and then close the HttpurlConnection. </p>

<p>i always endup getting the below error: </p>

<p>Cannot write output after reading input.
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)</p>

<p>public void sendEvents(ArrayList logList, HttpURLConnection conn) throws IOException
    {</p>

<pre><code>    DataOutputStream wr = null;


    try 
    {
         for(int i=0; i&lt;logList.size(); i++)
         {
          conn.connect();   
             wr = new DataOutputStream(conn.getOutputStream());
             wr.writeBytes(logList.get(i));
             wr.flush();
             int nothing = conn.getResponseCode();
             String morenothing = conn.getResponseMessage();
             wr.close();
             conn.disconnect();
         }   
         if(wr != null) {
             wr.close();
         }
    }
    catch (Exception e) 
    {
      e.printStackTrace();
    } 
    finally 
    {
      if(conn != null) 
      {
        conn.disconnect(); 
      }
    }
</code></pre>