WP7 HttpWebRequest 不带缓存
WP7 中的 HttpWebRequest 缓存似乎是默认启用的,如何关闭它? 添加随机数 param url + "?param=" + RND.Next(10000) 有效,但它非常棘手,我不确定它是否有效 与所有服务器。
It seems that HttpWebRequest caching in WP7 is enabled by default, how do I turn it off?
Adding a random
param url + "?param=" + RND.Next(10000) works, but it's quite tricky and I'm not sure if it will work
with all servers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我发现了 3 种方法
并更新你的 web.config
I found 3 ways
And update your web.config
添加随机数还不错,而且会起作用。我已经使用了 Time (在 ajax 调用中)。像文件夹一样放在url中。
Adding random number is not bad and it will work. I have used Time (in ajax call). Was placed in the url like a folder.
是的,这是可能的......:)我花了一周的实验,答案非常简单:
Yes is possible... :) I spend one week of Experiment and the answer is really simple :
为了将来的参考,这对我有用(由于项目要求,我无法使用额外的查询参数):
For future reference , this worked for me ( I could not use additional query parameter due to project requirements) :
对于 HttpClient(适用于 Windows Phone 的便携式),服务器端的“Cache-Control”:“no-cache”仅有时有效。我也无法将查询字符串随机值添加到 RESTful api 调用中。
@frno 的解决方案效果很好,看起来像 HttpClient:
谢谢。
In case of HttpClient (Portable for Windows Phone) "Cache-Control": "no-cache" on server side works only sometimes. And I cannot add query string random value to RESTful api call as well.
Solution from @frno works good and looks like for HttpClient:
Thank you.
您如何知道正在缓存的是手机,而不是服务器(或中间的代理)?
您是否使用 Fiddler2(或同等版本)检查过这一点?
您是否尝试过设置标头来禁用缓存?
像这样的东西:
How do you know it's the phone, not the server (or a proxy somewhere between) which is caching?
Have you checked this with Fiddler2 (or equivalent)?
Have you tried setting headers to disable caching?
Something like:
我们在 Chrome 中托管的 Silverlight 中看到了相同的行为。
如果我们想防止缓存,我们可以在请求 URL 中添加
"?nocache=" + DateTime.Now.Ticks.ToString()
。We've seen the same behaviour with Silverlight hosted in Chrome.
We add a
"?nocache=" + DateTime.Now.Ticks.ToString()
to our request URLs if we want to prevent caching.