OkHttp: avoid leaked connection warning

前端 未结 2 976
情话喂你
情话喂你 2021-02-03 20:12

I am using OkHttp 3, and I keep getting leaked connection warnings:

WARNING: A connection to https://help.helpling.com/ was leaked. Did you forget to close a res         


        
2条回答
  •  没有蜡笔的小新
    2021-02-03 20:26

    As mentioned in the other answers, you have to close the response. A slightly cleaner approach would be to declare the ResponseBody in the try block, so that it will be automatically closed.

    try(ResponseBody body = ....){
    ....
    }
    

提交回复
热议问题