Android xutils Framework Httputil GET request caching issues

Source: Internet
Author: User

In other words, today and the server developers a little tease, why?

Say today there is a "collection of products" request interface, is GET request of the Oh, my client to write the interface, click on the "Favorite button", Return to " collection success ", I ordered a bit, is actually still " collection success ", I again point, this next to, Return to Me "Cancel collection success", OK, I ordered a bit, thoroughly depressed, incredibly again "to cancel the collection success", this is not to tease me?

So I let the server personnel check his interface, is not what a moth, so strange. As a result he examined for half a day, feedback I was no problem, and let me go to his machine to see, he used the postman send the request interface for testing.

I look, ha, actually really no problem, I was wrong?

I looked back and checked again, yes, I wrote the code how can it be wrong? (Programmers have to be so confident)

So the war of tearing started, I let him check his server error, he let me check the client's fault .... Whose fault is it?

After a long day of tossing, I found the wrong place.

--is the Xutils framework Httputil GET request caching issue.


xutils Frame The HTTP module implements the work of the LRU cache when the GET request text content is added, which sets the default cache expiration time and the expiration time for the current request.

It sounds magical, xutils framework GET request incredibly implement the LRU cache, I actually do not know, actually made such a tease of the mistake.

Well, rewrite the Request tool class, the perfect tool class for everyone:

/** * Send HTTP request, automatically implement asynchronous processing * * @param URL Request address * @param params request parameters * @param ioauthc Allback Data Callback Interface */public static void SendRequest (final context context, final HTT         Pmethod method, String URL, requestparams params, final ioauthcallback ioauthcallback) {        LOGUTILS.D ("Requesturl:" + getabsoluteurl (URL));        Httputils http = new Httputils ();        Http.configcurrenthttpcacheexpiry (1000 * 5);        Set timeout Time Http.configtimeout (5 * 1000);        Http.configsotimeout (5 * 1000);        if (method==httpmethod.get) {http.configcurrenthttpcacheexpiry (0);//Set cache for 5 seconds and 5 seconds to return the results of the last successful request directly.                    } http.send (method, Getabsoluteurl (URL), params, new requestcallback<string> () { @Override public void OnStart () {LOGUTILS.D (Method.name () + ' request is '         OnStart ... ");           } @Override public void onsuccess (responseinfo<string> responseinfo                        {LOGUTILS.D ("StatusCode:" + responseinfo.statuscode + "----->" + responseinfo.result);                    Ioauthcallback.getioauthcallback (Responseinfo.result);//callback Data transfer with interface} @Override public void OnFailure (httpexception error, String msg) {logutils                        . D ("StatusCode:" + error.getexceptioncode () + "----->" + msg);    Ioauthcallback.getioauthcallback ("FF");//Use interface callback data transfer}}); }

Postscript:

Xutils Framework is a powerful third-party tool class framework, it has four modules, viewutil,dbtuls,bitmaputil,htputil, each tool class can complete the corresponding function of a module. Before I reproduced four blog introduction xutils, interested students can read, love to study the students can download source learning.

I used this framework for six months of application, the four modules have been used, the overall feeling of a word-convenient, cool!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android xutils Framework Httputil GET request caching issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.