{"id":7725,"date":"2015-10-19T01:10:02","date_gmt":"2015-10-19T01:10:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/19\/accessing-body-string-of-an-okhttp-response-twice-results-in-illegalstateexception-closed-open-source-projects-square-okhttp\/"},"modified":"2015-10-19T01:10:02","modified_gmt":"2015-10-19T01:10:02","slug":"accessing-body-string-of-an-okhttp-response-twice-results-in-illegalstateexception-closed-open-source-projects-square-okhttp","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/19\/accessing-body-string-of-an-okhttp-response-twice-results-in-illegalstateexception-closed-open-source-projects-square-okhttp\/","title":{"rendered":"Accessing body string of an OkHttp Response twice results in IllegalStateException: closed-open source projects square\/okhttp"},"content":{"rendered":"<p>I implement my http calls via the OkHttp library. Everything works fine, but I noticed that, when I access the body as a string of the response twice an <code>IllegalStateException<\/code> will be thrown. That is, I do (for example): <code>Log.d(\"TAG\", response.body().string())<\/code> and after that I actually want to use that string like <code>processResponse(response.body().string())<\/code>. But that second call throws the exception with the message <code>closed<\/code>.<\/p>\n<p>How can it be possible that accessing a string twice results in a failure? I want to process that response without the need to add a wrapper\/dummy object just for saving some values (like header, body, statuscode).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I implement my http calls via the OkHttp library. Everything works fine, but I noticed that, when I access the body as a string of the response twice an IllegalStateException will be thrown. That is, I do (for example): Log.d(&#8220;TAG&#8221;, response.body().string()) and after that I actually want to use that string like processResponse(response.body().string()). But that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7725","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7725"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7725\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}