3

因此,我想通过使用 Microsoft.XMLHTTP ActiveXObject 从 Windows 小工具中检索一些频繁更改的 JSON 数据。问题是它返回页面的缓存版本而不是请求新版本。

我无法控制服务器,也不能使用通常的发送额外参数的技巧,因为如果我发送任何参数,服务器会返回错误。

我已经用谷歌搜索死了,最好的信息在这个 Stackoverflow问题中,但没有一个答案对我有用;我一直无法从小工具 Javascript 中找到使用 ServerXMLHTTP 的方法。除了在 URL 中添加随机参数之外,我如何使用 ServerXMLHTTP,或防止以其他方式进行缓存?

4

3 回答 3

4

尝试使用 POST 而不是 GET

request = new ActiveXObject("Microsoft.XMLHTTP");
request.onreadystatechange = callback;
request.open("POST", "server.php", true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send();

参考: 防止 Chrome 缓存 AJAX 请求 和我自己的经验。

于 2013-07-28T18:18:13.127 回答
0

在 VBA 的上下文中添加一个随机数对我有用,例如

myURL= "http://acme.com/someapp/rest/someendpointurl?randombit=" & Rnd()

Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "username", "password"
WinHttpReq.send

myURL = WinHttpReq.responseBody
If WinHttpReq.status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write WinHttpReq.responseBody
    oStream.SaveToFile saveToPath, 2 ' 1 = no overwrite, 2 = overwrite
    oStream.Close
End If

谢谢 Sean Cull,您的解决方案在 VBA 环境中为我工作。

(不好意思,我不允许投票,所以在这里转发以供参考)

于 2020-12-07T10:23:15.677 回答
0

您不能在 URL 的末尾添加随机元素吗?您的http://acme.com/someapp/rest/someendpointurl?randombit=20171701143500

于 2017-01-17T14:35:20.273 回答