问题
I am doing an http GET to fetch data, I am using IXMLHTTPRequest2.
If I GET url "http://foo.com" (curl "http://foo.com"), the second time I get this url again, the content on server is actually changed, but what I am getting is the cached result.
Caching seems only honor URL, so if different header with same URL, still same cached result. I have tried "Cache-Control: no-cache", "Cache Control: no-store", and "Pragma: no-cache". None of them are honored by the API.
Is there a way to turn cache off or walk around? (One walk around I am using is appending garbage at end of URL but I am not feeling good with it).
回答1:
my question got answered here by Prashant: http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/1df95d3e-68c9-4351-822a-c2cfde380248/#1df95d3e-68c9-4351-822a-c2cfde380248
You can force XHR to retrieve the latest content by setting the "If-Modified-Since" HTTP header in the request and set a time in the past. If you have control over the server response, you could send back an Expires HTTP response header with a value 0 or a date in the past. That should make XHR retrieve the latest response for you.
You are only required to do one of the above, changing both the client and server side code is not necessary.
The client side code could be changed to something like this:
xhr->Open(...)
xhr->SetRequestHeader(L"If-Modified-Since", L"Sat, 01 Jan 2000 00:00:01 GMT");
xhr->Send(...)
For changing the server side behavior if your server side code is based on ASP.net you could change your response header like this:
Response.Headers.Add("Expires", "0")
回答2:
I think you need to use sockets.....i think these two links should help
C# WebClient disable cache
How do I Create an HTTP Request Manually in .Net?
来源:https://stackoverflow.com/questions/13130739/how-to-disable-caching-http-get-in-metro-app-i-am-using-ixmlhttprequest2