WP7 - Prevent RestSharp from caching

Deadly 提交于 2019-12-05 02:06:02

问题


I use RestSharp in my Windows Phone 7.1 project.

My problem is RestSharp always cache response data.

Example:

At the first time I send request, it returns data correctly. After some delete operations, I send that request again, but response seems the same as the first time, nothing's changed.

If I stop debugging and press F5 to start again, it works perfectly as expected.

I also tried request.AddParameter("cache-control", "no-cache", ParameterType.HttpHeader); and got no luck.

How can I fix this problem?


回答1:


I have the same issue so just add header that specify not to cache response data client is my RestClient with base url and than add default header Cache-Control with value no-cache.

client.AddDefaultHeader("Cache-Control", "no-cache")



回答2:


I found solution in Rico Suter comment, thanks! I will mark this as accepted anwser

its a hack but try something like url = originalUrl + "&nocache=" + DateTime.Now.Ticks




回答3:


The "Cache-Control" header should do the trick!

I think HTTP Headers are case-insensitive, but the server may not agree with me there! You should try using Cache-Control instead of cache-control...

Also, I would also add the Pragma header with no-cache value to the request (some old servers don't use the "Cache-Control" header, but they will sure recognize this one)!

And I would try to use Fiddler to debug the comms and check that the headers are really being sent to the server as expected!




回答4:


Another solution can be to set the "If-Modified-Since" header with value of DateTime.Now:

client.AddDefaultParameter("If-Modified-Since", DateTime.Now, ParameterType.HttpHeader);


来源:https://stackoverflow.com/questions/10232514/wp7-prevent-restsharp-from-caching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!