How do you disable caching with WebClient and Windows Phone 7

后端 未结 4 1984
攒了一身酷
攒了一身酷 2020-12-20 17:02

I am making a call to a REST web service and the mobile app is retrieving the results from its cache and not going to the server.

I have seen other suggested fixes (

相关标签:
4条回答
  • 2020-12-20 17:13

    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));
    
    0 讨论(0)
  • 2020-12-20 17:26

    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.

    0 讨论(0)
  • 2020-12-20 17:30

    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;
    
    0 讨论(0)
  • 2020-12-20 17:32
    WebClient wc = new WebClient();
    wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
    

    worked for me

    0 讨论(0)
提交回复
热议问题