[JAVA] Correspondence to A connection to XXXX was leaked.

Overview

How to deal with the following error that occurred when using Http (s) URLConnection during Android development with Java

A connection to XXXX was leaked. Did you forget to close a response body?

solution

It's not a big story, and it seems that getInputStream () side and getErrorStream () side need close respectively.

HttpsURLConnection URLconnection = null;

<Abbreviation>

if (URLconnection.getErrorStream() != null){
 try {
  URLconnection.getErrorStream().close();
 }catch (IOException e){
  e.printStackTrace();
 }
}

Reference URL

https://docs.oracle.com/javase/jp/8/docs/api/javax/net/ssl/HttpsURLConnection.html

Recommended Posts

Correspondence to A connection to XXXX was leaked.
I was a little addicted to ssh connection from mac to linux (ubuntu)
A story that took time to establish a connection
A story I was addicted to in Rails validation settings