English 中文(简体)
• 如何检查在Default的殴打 HttpClient Anders
原标题:How to check caching in DefaultHttpClient on Android

我的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在答复内容上加固,在到期之前不再向服务器提出要求?

问题回答

http://hc.apache.org/http://components-client-ga/tutorial/html/caching.html 这可能是你所期望的,它只是对过失的cor击。 HttpClient。

请注意,只有HttpClient 4.0,才能使样本代码在roid中发挥作用,因此,你需要将HttpClient 4.1和HttpClient Cache 4.1增列入项目。

您可使用ts

Its a 704kb library and contains a parallel implementation of httpclient 4.1 compiled for Android. It contains CachingHttpClient and many bug fixes as well. However only use if in-memory cache is useful for you. So if your application makes the same api call many times during one session the performance impact will be visible.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签