How to prevent Android from returning a cached response to my HTTP Request?

后端 未结 3 1417
说谎
说谎 2020-12-02 23:06

I\'m writing a client that is making repeated http requests for xml data that is changing over time. It looks like the Android stack is caching my page requests and returni

相关标签:
3条回答
  • 2020-12-02 23:42

    Hint: to get the random string

    HttpGet request = new HttpGet(url + "?unused=" + UUID.randomUUID().toString());
    
    0 讨论(0)
  • 2020-12-02 23:56

    add a HTTP header:

    Cache-Control: no-cache
    

    and see if that works.

    0 讨论(0)
  • 2020-12-02 23:56

    Append an unused parameter on the end of the URL:

    HttpGet request = new HttpGet(url + "?unused=" + someRandomString());
    

    where someRandomString() probably involves the current time.

    It's crude, but it's pretty much guaranteed to work regardless of all the outside factors that can make a "proper" solution fail, like misconfigured or buggy proxies.

    0 讨论(0)
提交回复
热议问题