HttpUrlConnection that sends multiple post request in single connection
<p>I want to make multiple post calls in a single HTTP connection, </p>

<ol>
<li>I will be sending an <code>Arraylist&lt;String&gt;</code> and <code>httpConnection</code> objects as the input parameters.</li>
<li>Iterate the <code>ArrayList</code> and write the request to the server.</li>
</ol>

<p>I end up getting the below error :</p>

<pre><code>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)
</code></pre>

<p>Here is my code. I am using to accomplish the above task.</p>

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

    return false;
}
</code></pre>

<p>How can I overcome this situation?</p>