我需要有关持久性httpurlconnection
的帮助我的方法标题看起来像
public boolean sendToAPI(ArrayList logs) {
}
我需要能够通过迭代日志列表打开HttpUrlConnection并调用多个post请求,然后关闭HttpurlConnection。
我总是得到以下错误:
读取输入后无法写入输出。 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)抛出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();
}
}