REST API GET 调用从 VBA 使用 XmlHttp 不会在第一次调用后获取最新数据

问题描述

我一直在努力完成这项工作。我有一个试图通过 REST API 获取数据的 VBA 代码。它在第一次运行时确实获得了正确的数据,但在第二次之后它没有获得更新的数据,而是获得了与第一次调用相同的数据。每次我多次调用 GET 调用时,这个问题都是可复制的。

我的 VBA 代码如下(上面的“第二次运行”表示第二次运行 Main):

Sub Main()
    
    Dim MyHtml As String
    Dim MyXmlResponse As String

    MyHtml = "..."
    
    MyXmlResponse = DoRestCall(MyHtml,"GET") ' Result in the second or later run is always the same as in the first run even the data is updated

End Sub


Function DoRestCall(Html As String,RestCallAction)

    Dim XmlHttp As Object
    Dim XmlHttpResponse As String

    Set XmlHttp = CreateObject("MSXML2.XMLHTTP")
    Call XmlHttp.Open(RestCallAction,Html,False)
    
    XmlHttp.setRequestHeader "Authorization","Basic " + _
        "EncodedCredntial"

    XmlHttp.setRequestHeader "Content-Type","application/json"
    
    Call XmlHttp.Send
    
    XmlHttpResponse = XmlHttp.responseText
    DoRestCall = XmlHttpResponse
    
    Set XmlHttp = nothing
    
End Function

有人能告诉我我遗漏了什么吗?如果需要更多信息/说明,请告诉我。

谢谢和问候, 京都

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)