Android JSON停止缓存(Android JSON stop caching)

编程入门 行业动态 更新时间:2024-10-28 10:27:20
Android JSON停止缓存(Android JSON stop caching)

有人知道如何在发出JSON请求时停止缓存吗? 在我的JSON请求标头中,我有用户名和密码,我的问题是:

首先我输入正确的数据(正确的用户名和密码) - >请求成功 从上面的步骤后,我介绍了一个正确的用户名,但错误的密码 - >请求仍然成功,它不应该 然后我用Force Stop关闭我的应用程序并输入错误的密码。 现在请求失败,这是好的。

但我不明白为什么我必须强制停止应用程序才能获得请求的正确状态。 我想到的唯一想法就是以某种方式缓存数据。 如果我的想法是正确的,我怎么能阻止缓存? 我将不胜感激!

How can I stop caching when a JSON request is made? In my JSON request headers I have username and password and my problem is:

first I put the correct data (correct username and password) -> The request is successful after the step from above I introduce a correct username but a wrong password -> The request is still successful and it shouldn't then I am closing my app with Force Stop and let the wrong password. Now the request fails which is Ok.

But I don't understand why I have to Force Stop the app in order to get the correct status of the request. The only thought that crossed my mind is that somehow the data is cached. If my thoughts are correct how can I prevent the caching?

最满意答案

我已经弄明白问题是什么了。 当我更改密码时,会话未关闭,并且它与旧数据连接。 所以我不得不使用这段代码“注销”:

client.getConnectionManager().closeExpiredConnections(); client = null;

然后我创建了一个新的Http客户端。

I have figured it out what the problem was. When I changed the password the session was not closed and it was connecting with the old data. So I had to make a "log out" using this code:

client.getConnectionManager().closeExpiredConnections(); client = null;

And then I created a new Http Client.

更多推荐

本文发布于:2023-04-29 08:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   JSON   Android   stop   caching

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!