VBScript:禁用服务器对 HTTP GET URL 请求的响应缓存

发布于 2024-09-06 13:43:40 字数 1342 浏览 4 评论 0 原文

我想关闭从 Windows 计算机上的应用程序中运行的 VBScript 对服务器进行 URL 调用时使用的缓存。我使用什么函数/方法/对象来执行此操作?

当第一次调用时,我的基于 Linux 的 Apache 服务器会从它正在运行的 CGI Perl 脚本返回响应。但是,脚本的后续运行似乎使用与第一次相同的响应,因此数据被缓存在某处。我的服务器日志确认该服务器在随后的时间里没有被调用,只有在第一次时才被调用。

这就是我正在做的事情。我正在商业应用程序中使用以下代码(不想提及此应用程序,可能与我的问题无关):


With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://myserver/cgi-bin/nsr/nsr.cgi?aparam=1", False
  .send
  nsrresponse =.responseText
End With

上述对象上是否有函数/方法来关闭缓存,或者我应该调用在创建 URL 之前关闭响应对象上的缓存的方法/函数?

我在这里寻找解决方案: http://msdn.microsoft .com/en-us/library/ms535874(VS.85).aspx - 不够有帮助。这里: http://www.w3.org/TR/XMLHttpRequest/ - 非常不友好且难以阅读。

我还尝试使用 http 标头设置和 html 文档标头元数据强制不使用缓存:

将响应返回到调用客户端的服务器端 Perl CGI 脚本的片段,将到期设置为 0。


    print $httpGetCGIRequest->header(
        -type    => 'text/html',
        -expires => '+0s',
        );

发送的响应中的 Http 标头设置回到客户端:


<html><head><meta http-equiv="CACHE-CONTROL" content="NO-CACHE"></head>
<body>
response message generated from server
</body>
</html>

上面的http标头和html文档头设置不起作用,因此我的问题。

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 to do this?

When the call is made for the first time, my Linux based Apache server returns a response back from the CGI Perl script that it is running. However, subsequent runs of the script seem to be using the same response as for the first time, so the data is being cached somewhere. My server logs confirm that the server is not being called in those subsequent times, only in the first time.

This is what I am doing. I am using the following code from within a commercial application (don't wish to mention this application, probably not relevant to my problem):


With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://myserver/cgi-bin/nsr/nsr.cgi?aparam=1", False
  .send
  nsrresponse =.responseText
End With

Is there a function/method on the above object to turn off caching, or should I be calling a method/function to turn off the caching on a response object before making the URL?

I looked here for a solution: http://msdn.microsoft.com/en-us/library/ms535874(VS.85).aspx - not quite helpful enough. And here: http://www.w3.org/TR/XMLHttpRequest/ - very unfriendly and hard to read.

I am also trying to force not using the cache using http header settings and html document header meta data:

Snippet of server-side Perl CGI script that returns the response back to the calling client, set expiry to 0.


    print $httpGetCGIRequest->header(
        -type    => 'text/html',
        -expires => '+0s',
        );

Http header settings in response sent back to client:


<html><head><meta http-equiv="CACHE-CONTROL" content="NO-CACHE"></head>
<body>
response message generated from server
</body>
</html>

The above http header and html document head settings haven't worked, hence my question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙女 2024-09-13 13:43:40

我认为 XMLHTTP 对象本身甚至没有实现缓存。

当您调用 .send() 时,您就发送了一个新的请求。缓存的全部目的是避免发送请求,但这里不会发生这种情况(就您的代码示例而言)。

但是如果该对象在某种浏览器中使用,那么浏览器可能会实现缓存。在这种情况下,常见的方法是在语句中包含一个缓存破坏器:每次发出新请求时都会更改的随机 URL 参数(例如,将当前时间附加到 URL)。

或者,您可以让服务器发送 Cache-Control: no-cache, no-store HTTP 标头,看看是否有帮助。

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.

远昼 2024-09-13 13:43:40

您可以使用 WinHTTP,它不缓存 HTTP 响应。您仍然应该使用 SetRequestHeader 方法,因为它指示中间代理和服务器不要返回先前缓存的响应。

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.

你没皮卡萌 2024-09-13 13:43:40

如果您可以控制 XMLHTTP 请求所针对的应用程序(在您的情况下是这样),您可以让它在响应中发送无缓存标头。这解决了我的案例中的问题。

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

作为替代方案,您还可以将包含随机数的查询字符串附加到每个请求的 URL。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文