解決okhttp報java.lang.IllegalStateException: closed,java.lang.IllegalStateException: closed
from : http://blog.csdn.net/x707669224/article/details/56280270
解決okhttp 報java.lang.IllegalStateException: closed,java.lang.IllegalStateException: closed,原因為OkHttp請求回撥中response.body().string()只能有效呼叫一次
在呼叫了response.body().string()方法之後,response中的流會被關閉,我們需要建立出一個新的response給應用層處理。不多說直接貼程式碼:
@Override
public Response intercept(Chain chain) throws IOException
{
Request request = chain.request();
logForRequest(request);
Response response = chain.proceed(request);
MediaType mediaType = response.body().contentType();
String content= response.body().string();
Log.e("tag", content);
return response.newBuilder()
.body(ResponseBody.create(mediaType, string))
.build();
// return logForResponse(response);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
相關文章
- java.lang.IllegalStateException: closedJavaException
- android java.lang.IllegalStateException: trying to requery an already closed cursorAndroidJavaException
- [求助]SQLException: ResultSet is closedSQLException
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解決方案JavaException
- 支付寶轉賬介面HTTP/2 stream 0 was not closed close cleanly報錯解決HTTP
- java.lang.IllegalStateException: getWriteableDatabase called recursivelyJavaExceptionDatabase
- 3.2.2 Opening a Closed DatabaseDatabase
- 解決Hibernate session is closed的一種可行性方案Session
- java.lang.IllegalStateException: Service id not legal hostnameJavaException
- ORA-12537: TNS:connection closed問題解決
- client backup was not attempted because backup window closed 錯誤解決一例client
- Spider closed (finished) 沒完成IDE
- 一個異常org.apache.jasper.JasperException: java.lang.IllegalStateException: No output folder:的解決...ApacheExceptionJava
- Idea啟動專案報{dataSource-1} closed錯誤Idea
- Unable to unwrap data, invalid status [CLOSED]-服務端webSocket報錯服務端Web
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解讀JavaExceptionErrorMIT
- java.lang.IllegalStateException: getOutputStream() has already been called for this responseJavaException
- java.lang.IllegalStateException:YouneedtouseaTheme.AppCompatthemeJavaExceptionAPP
- Caused by: java.lang.IllegalStateException: getWriter() has already been called for this responseJavaException
- python程式碼錯誤RuntimeError: Session is closedPythonErrorSession
- 解決11gR2 Rac ORA-12537: TNS:connection closed 一例
- Oracle 12c RMAN Cross-Platform Transport of a Closed PDBOracleROSPlatform
- ssh問題:ssh_exchange_identification: Connection closed by remote hostIDEREM
- 求助:移動端登入測試,報錯 RemoteDisconnected Remote end closed connection without response。REM
- 設計模式筆記:開閉原則(OCP,The Open-Closed Principle)設計模式筆記
- /dev/root filesystem full-unable to log into server-This thread has been closeddevServerthread
- sqlplus scott/system@ora10g報錯ORA-12537: TNS:connection closedSQL
- error: RPC failed; curl 18 transfer closed with outstanding read data remainingErrorRPCAIREM
- Mysql異常刨析:Could not commit JDBC transaction;No operations allowed after statement closedMySqlMITJDBC
- 【Oracle】ORA-12537: TNS:connection closed 問題處理Oracle
- ora-12537 TNS:connection closed的問題處理
- Emily Dickinson的詩歌《My Life Closed Twice Before Its Close》
- ViewPager內使用FragmentPagerAdapter時滑動出現 java.lang.IllegalStateException: The specified child already hViewpagerFragmentAPTJavaException
- Caused by: java.lang.IllegalStateException: Only single-level inheritance supported: XxxxServiceJavaException
- SAP MM 採購申請單據ITEM資料裡的Closed標記
- IgniteFAQ-10-使用hikariDataSource資料來源偶現日誌報錯load資料包connection is closed
- rhel5上配置vsftpd_421 Service not available, remote server has closed connectionFTPAIREMServer
- FI-AA Capitalization date 2012.08.01 not before closed FY 2012API