[removed] Disable caching of response from server to HTTP GET URL request

后端 未结 3 1926
一整个雨季
一整个雨季 2020-12-06 11:31

I want to turn off the cache used when a URL call to a server is made from VBScript running within an application on a Windows machine. What function/method/object do I use

相关标签:
3条回答
  • 2020-12-06 11:53

    You could use WinHTTP, which does not cache HTTP responses. You should still add the cache control directive (Cache-control: no-cache) using the SetRequestHeader method, because it instructs intermediate proxies and servers not to return a previously cached response.

    0 讨论(0)
  • 2020-12-06 11:59

    I don't think that the XMLHTTP object itself does even implement caching.

    You send a fresh request as soon as you call .send() on it. The whole point of caching is to avoid sending requests, but that does not happen here (as far as your code sample goes).

    But if the object is used in a browser of some sort, then the browser may implement caching. In this case the common approach is to include a cache-breaker into the statement: a random URL parameter you change every time you make a new request (like, appending the current time to the URL).

    Alternatively, you can make your server send a Cache-Control: no-cache, no-store HTTP-header and see if that helps.

    The <meta http-equiv="CACHE-CONTROL" content="NO-CACHE> is probably useless and you can drop it entirely.

    0 讨论(0)
  • 2020-12-06 12:04

    If you have control over the application targeted by the XMLHTTP Request (which is true in your case), you could let it send no-cache headers in the Response. This solved the issue in my case.

    Response.AppendHeader("pragma", "no-cache");
    Response.AppendHeader("Cache-Control", "no-cache, no-store");
    

    As alternative, you could also append a querystring containing a random number to each requested url.

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