在MSXML2.xmlHttp中发送方法不发送第二次

0 vb6

我使用以下代码并使用此创建一个DLL.第一次发送方法很好.从那时起,它给出的旧值不是更新的值

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
Run Code Online (Sandbox Code Playgroud)

谢谢阿莎

小智 5

你可以做一个非常简单的技巧来获得更新的值,你必须总是有一个不同的URL.在每次发送请求时更改的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
Run Code Online (Sandbox Code Playgroud)

祝好运 ;)