gpt4 book ai didi

ios - 如何停止在 ionic 3 中缓存我的 HTTP 请求和响应

转载 作者:技术小花猫 更新时间:2023-10-29 11:24:55 25 4
gpt4 key购买 nike

我想停止缓存我的 API 请求和响应,native-http 插件存储了它的缓存及其对我的应用造成的问题。

All-time API 工作正常,但当我从服务器收到 404 或 401 错误时,它会将其缓存在我的应用程序中,然后在所有时间后我将收到状态为 1 的超时错误。

为了解决这个问题,我需要卸载应用程序并重新安装它才能正常工作。

知道如何停止缓存 HTTP 请求和响应吗?

或者如何解决状态为1的超时问题?

我已经在我的请求 header 中尝试了以下内容,但仍然没有成功。

self.httpPlugin.setHeader('*', 'authorization', 'Bearer ' + token);
self.httpPlugin.setHeader('*', 'Cache-control', 'no-cache');
self.httpPlugin.setHeader('*', 'Cache-control', 'no-store');
self.httpPlugin.setHeader('*', 'Expires', '0');
self.httpPlugin.setHeader('*', 'Pragma', 'no-cache');

还在我的请求中添加了一个虚拟唯一参数,以发出我的 API 调用的唯一请求,如下所示。

self.httpPlugin.setHeader('*', 'ExtraDate', new Date().toString());

有人在 Ionic 3 中遇到过此类问题吗?

已尝试 this线程建议,但一点运气都没有。

针对此问题提出任何解决方案。

编辑:

完整请求代码:

/**
* Get Search result from server.
*/
getCaseListBySearchText(searchText: string): Observable<any> {
let self = this;

return Observable.create(function(observer) {
self.getToken().then(token => {
console.log("Token : ", token);

// let rand = Math.random();
self.httpPlugin.setHeader("*", "authorization", "Bearer " + token);
self.httpPlugin.setHeader("*", "Cache-control", "no-cache");
self.httpPlugin.setHeader("*", "Cache-control", "no-store");
// self.httpPlugin.setHeader("*", "Expires", "0");
self.httpPlugin.setHeader("*", "Cache-control", "max-age=0");
self.httpPlugin.setHeader("*", "Pragma", "no-cache");
self.httpPlugin.setHeader("*", "ExtraDate", new Date().toString());

self.httpPlugin
.get(self.url + "/CaseList?caseNum=" + searchText, {}, {})
.then(response => {
console.log("Response Success : " + JSON.stringify(response));
let jsonResponse = JSON.parse(response.data);
console.log("JSON OBJECT RESPONSE : " + jsonResponse);
observer.next(jsonResponse);
})
.catch(error => {
if (error.status == 403) {
console.log("Token expired : " + JSON.stringify(error));
self.isTokenExpired = true;
//Removing Old Token
self.storage.remove(Constants.AUTH_DATA);
observer.error(error);
} else {
console.log("Error : " + error);
console.log("Error " + JSON.stringify(error));
observer.error(error);
}
});
})
.catch(error => {
console.log("Error : " + error);
observer.error(error);
});
});


}

最佳答案

在针对上述问题进行大量研发和网络搜索之后,我找到了一个清理请求缓存的解决方案,因为上面所有的 header 都无法清理缓存。

在 HTTP Advanced 插件中,有一种方法可以清除我的 cookie。

clearCookies()

Clear all cookies.

通过在我的类构造函数中使用上述方法在调用任何 API 之前清除 cookie。

那么它会做什么清除我所有的 cookie,我与旧 cookie 相关的问题将以这种方式解决。

constructor(
public storage: Storage,
public httpPlugin: HTTP,
private platform: Platform
) {
// enable SSL pinning
httpPlugin.setSSLCertMode("pinned");
//Clear old cookies
httpPlugin.clearCookies();
}

上面的代码解决了我的问题。

感谢大家的快速指导和建议。

如果这不是清除我的旧请求数据的正确方法,请对此发表评论。

关于ios - 如何停止在 ionic 3 中缓存我的 HTTP 请求和响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52698596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com