1

如果没有互联网连接,应用程序应提供来自服务器的最后数据。使用 HttpResponseCache 作为保存所有 http 请求以在离线模式下使用它们的工具是个好主意吗?

现在,当我禁用 Internet 连接时,出现异常:

java.net.UnknownHostException: Unable to resolve host

我应该将数据写入磁盘,并在离线模式下使用它吗?

PS我配置了HttpResponseCache,并使用HttpURLConnection:

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("Cache-Control", "max-stale=" + maxStale);
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
connection.setRequestMethod("GET");
connection.setUseCaches(true);
connection.setDoInput(true);
connection.connect();
4

0 回答 0