在使用Okhttp的時候
運行到response.body().string()一步時拋異常,java.lang.IllegalStateException: closed
查閱各種資料大致意思是The IllegalStateException
arises because the HttpConnection seems to be closed when trying to use it. Could it be because you are calling twice the method response.body()
?
就是說調用response.body().string()的時候數據流已經關閉了,再次調用就是提示已經closed,
檢查代碼發現,其他的地方並沒有調用過response.body().string(),而且是調試的時候有,后來發現是在debug的時候添加了Watchs,就是代碼的監視,這里會調用一次response.body().string()。
后面需要注意,代碼調試的時候表達式的監視有時候會影響代碼的運行。