2011-12-26 70 views
0

我正在使用以下代码并使用此创建一个dll。第一次发送方法很好。从那时起,它给旧值不更新的值MSXML2.xmlHttp发送方法不发送第二次

Dim xmlHttp As MSXML2.xmlHttp 
Set xmlHttp = New MSXML2.xmlHttp 
Dim response as string 
response = xmlHttp.readyState 
sUrl = "MyUrl" 
xmlHttp.open "GET", sUrl, False 
xmlHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
response = xmlHttp.readyState 
xmlHttp.send 

response = xmlHttp.readyState 
response = xmlHttp.responseText 
..... 
Set xmlHttp = Nothing 

感谢 阿莎

+0

也许你应该通读http://stackoverflow.com/questions/5235464/how-to-make-microsoft-xmlhttprequest-honor-cache-control-directive – Bob77 2011-12-26 18:33:26

+0

你真的每次都重新创建对象吗? – Deanna 2012-10-02 10:01:07

回答

4

你可以做一个非常简单的手段来得到总是更新的值,必须始终有一个不同的URL。 在改变每次发送请求时将网址添加参数,该参数不执行任何操作在服务器端 在这个例子中,我创建递增在每次调用

Function GetHTMLSource(ByVal sURL As String) As String 
Static id As Long 
    id = id + 1 
    If id >= 60000 Then 
     id = 0 
    End If 
    Dim xmlHttp As Object 
    Set xmlHttp = CreateObject("MSXML2.XmlHttp") 
    xmlHttp.Open "GET", sURL & "?i=" & id, False 
    xmlHttp.Send 
    GetHTMLSource = xmlHttp.responseText 
    Set xmlHttp = Nothing 
End Function 

运气好一个静态变量;)