How do you disable caching with WebClient and Windows Phone 7

折月煮酒 提交于 2019-11-29 13:32:00

Although not ideal, a easy solution is to send something like the field "junk" with the value DateTime.Now. That way, a value is always brand new, and will never get cached. If you were doing this in a standard querysting for example:

"&junk=" + DateTime.Now;

I've hit this problem too on overflow 7 talking to StackApps - the only thing I could think of was to add an addition random variable to the end of the HTTP/REST request.

The most proposed solution is the same as William Melani's. But it is not ideal and some services reject requests with unknown parameters or any parameter. In this case it is cleaner and more reliable to use the IfModifiedSince header as follows:

    WebClient wc = new WebClient();
    wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
    wc.DownloadStringCompleted += wc_DownloadStringCompleted;
    wc.DownloadStringAsync(new Uri(bitstampUrl));
mohan raj
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();

worked for me

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