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

主宰稳场 提交于 2019-11-27 12:22:47
Kylar

add a HTTP header:

Cache-Control: no-cache

and see if that works.

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.

Flavio Battocchio

Hint: to get the random string

HttpGet request = new HttpGet(url + "?unused=" + UUID.randomUUID().toString());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!