显示MS Access中HTTP请求的进度 [英] Show progress of HTTP Request in MS Access

查看:110
本文介绍了显示MS Access中HTTP请求的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码,从API获取数据并将数据添加到表中.我想向用户展示API Request Made的进度.因此,使用If使用readyState Property (IXMLHTTPRequest)

I am using the below code, to get data from API and add data to table. I want to show the users the progress of the API Request Made. Hence using If to get the status of the request using readyState Property (IXMLHTTPRequest)

问题-

调用此函数时,我只得到一个带有4的msgbox. 我想念什么?

When this function is called, I just get one msgbox with 4. What am I missing??

Option Compare Database

Dim ApiUrl As String
Dim reader As New XMLHTTP60
Dim coll As Collection
Dim Json As New clsJSONParser

Public Sub ApiInitalisation()
    ApiUrl = "http://private-anon-73376961e-countingappapi.apiary-mock.com/"
End Sub

Public Sub GetPerson()
On Error GoTo cmdLogIn_Click_Err

    'For API
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim contact As Variant

    Api.ApiInitalisation
    ApiUrl = ApiUrl & "users/5428a72c86abcdee98b7e359"

    reader.Open "GET", ApiUrl, False
    'reader.setRequestHeader "Accept", "application/json"
    reader.send

    'Temporay variable to store the response
    Dim egTran As String

相关代码开始

    If reader.ReadyState = 0 Then
    MsgBox (0)
    End If

    If reader.ReadyState = 1 Then
    MsgBox (1)
    End If

    If reader.ReadyState = 2 Then
    MsgBox (2)
    End If

    If reader.ReadyState = 3 Then
    MsgBox (3)
    End If

    If reader.ReadyState = 4 Then
    MsgBox (4)
    End If


    '-------------
    ' Why is this code required?
    ' Not yet found answer

    'Do Until reader.ReadyState = 4
    '   DoEvents
    'Loop
    '-------------------

相关代码结束

    ' Add data to Table
    If reader.Status = 200 Then
        Set db = CurrentDb
        Set rs = db.OpenRecordset("tblPerson", dbOpenDynaset, dbSeeChanges)

        egTran = "[" & reader.responseText & "]"
        Set coll = Json.parse(egTran)

        For Each contact In coll
            rs.AddNew
            rs!FName = contact.Item("name")
            rs!Mobile = contact.Item("phoneNumber")
            rs!UserID = contact.Item("deviceId")
            rs!SID = contact.Item("_id")
            rs.Update
        Next

    Else
        MsgBox "Unable to import data."
    End If

End Sub

根据 Microsoft文档

0(未初始化)=

对象已创建,但尚未初始化(尚未调用open方法).

The object has been created, but not initialized (the open method has not been called).

(1)加载=

对象已创建,但未调用send方法.

The object has been created, but the send method has not been called.

(2)LOADED =

(2) LOADED =

已调用send方法,但是状态和标头尚不可用.

The send method has been called, but the status and headers are not yet available.

(3)交互式=

已接收到一些数据.在此状态下调用responseBody和responseText属性以获得部分结果将返回错误,因为状态和响应标头不完全可用.

Some data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.

(4)已完成=

已接收到所有数据,并且可以在responseBody和responseText属性中找到完整的数据.

All the data has been received, and the complete data is available in the responseBody and responseText properties.

推荐答案

除非您缺少一些代码或引起误解,否则您已经在使用reader.send prior 来检查ReadyState. .除非遇到致命错误,否则它将始终以已完成"状态返回(即使这样,它也可能会以已完成"状态返回).

Unless you're missing some code or I'm misunderstanding, you're already using reader.send prior to checking the ReadyState. It's always going to come back as Completed, unless it encounters a fatal error (and even then it may come back as Completed).

这篇关于显示MS Access中HTTP请求的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆