2011-12-26 69 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 

運氣好一個靜態變量;)