我的Anderson应用要求使用DefaultHttpClient的网络服务电话来保存答复文本。 海滩应有效,直至Http回复头确定的到期日。
I found similar questions but they were complaints that the DefaultHttpClient is caching their responses. Funny I need it but could not get working. Or there solutions suggested that are file based.
Does Android keeps the images downloaded from HTTP in cache?
how to do image caching in android
我写了一张样本,显示有人要求用陶器点击ton子,并打印反应状况和头盔。
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response;
response = client.execute(request);
System.out.println("Response status - " + response.getStatusLine().getStatusCode());
我的《公认会计原则》是:
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
resp.setHeader("Expires", "Wed, 11 Jul 2012 12:00:00 GMT");
resp.setHeader("Cache-Control", "max-age=2592000");
resp.getWriter().println("Hi!");
}
每一次在纽特州进行点击,使我享有200个地位法。 我只想第一次这样做。
Response status - 200
***** Response Headers *****
Content-Type - text/plain; charset=iso-8859-1
Expires - Wed, 11 Jul 2012 12:00:00 GMT
Cache-Control - max-age=2592000
Date - Wed, 13 Jul 2011 06:54:57 GMT
Server - Google Frontend
Transfer-Encoding - chunked
I edited the servlet and published; the client reads the latest change. I tested the servlet application on Chrome browser and caching works fine.
I added the Cache-control property in the request header, but did not get the expected result.
我如何确保DefaultHttpClient在答复内容上加固,在到期之前不再向服务器提出要求?