【发布时间】:2016-02-27 20:44:40
【问题描述】:
我正在尝试查看何时从我的 API 收到代码 401 的响应。 但是当我这样做时,我得到一个 IOException
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
if (response.code() == 401) {
mLoginToken.delete();
Toast.makeText(mApplication.getApplicationContext(), R.string.session_error, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(mApplication.getApplicationContext(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
mApplication.startActivity(intent);
}
return response;
}
我会得到错误 java.io.IOException: Connection{ proxy=DIRECT@ hostAddress= cipherSuite=none protocol=http/1.1} (recycle count=0)
上的流意外结束排队
Response response = chain.proceed(request);
我应该如何获得带有 401(未经授权的代码)的响应以处理此问题?
【问题讨论】: