I need help regarding the persistent httpurlconnection
my method header looks like
public boolean sendToAPI(ArrayList logs) {
}
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.
i always endup getting the below error:
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)
public void sendEvents(ArrayList logList, HttpURLConnection conn) throws IOException {
DataOutputStream wr = null;
try
{
for(int i=0; i<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();
}
}