gpt4 book ai didi

api - 创建与基于 REST 的 API 的 Microsoft Access 数据库连接

转载 作者:行者123 更新时间:2023-12-02 11:25:24 28 4
gpt4 key购买 nike

我正在尝试在 Microsoft Access 2013 中创建指向基于 REST 的 API ( this API, to be specific ) 提供的数据的实时链接。最终目标是让数据在查询中可用,就好像它是本地数据库一样。

如何实现这一点?具体来说,我正在努力解决如何让 Access 根据请求调用 API。我认为实现类似结果的唯一方法是编写一个脚本,通过 API 提取整个数据库并将其转换为 Access 可读格式,然后按设定的时间间隔运行该脚本。但我真的很想找到一个实时工作的解决方案,即使它比本地缓存数据库慢一点。

最佳答案

由于对 RESTful Web 服务的调用实际上只是一种特定类型的 HTTP 请求,因此您至少可以使用 Microsoft XML 库向 Web 服务发出 HTTP 请求并解析它返回的任何内容。例如,当我运行以下 VBA 代码时

' VBA project Reference required:
' Microsoft XML, v3.0

Dim httpReq As New MSXML2.ServerXMLHTTP
httpReq.Open "GET", "http://whois.arin.net/rest/poc/KOSTE-ARIN", False
httpReq.send
Dim response As String
response = httpReq.responseText
Debug.Print response

字符串变量response包含对我的请求的XML响应。它看起来像这样(为了可读性而重新格式化后):

<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='http://whois.arin.net/xsl/website.xsl' ?>
<poc xmlns="http://www.arin.net/whoisrws/core/v1" xmlns:ns2="http://www.arin.net/whoisrws/rdns/v1"
xmlns:ns3="http://www.arin.net/whoisrws/netref/v2" termsOfUse="https://www.arin.net/whois_tou.html"
inaccuracyReportUrl="http://www.arin.net/public/whoisinaccuracy/index.xhtml">
<registrationDate>2009-10-02T11:54:45-04:00</registrationDate>
<ref>http://whois.arin.net/rest/poc/KOSTE-ARIN</ref>
<city>Chantilly</city>
<companyName>ARIN</companyName>
<iso3166-1>
<code2>US</code2>
<code3>USA</code3>
<name>UNITED STATES</name>
<e164>1</e164>
</iso3166-1>
<firstName>Mark</firstName>
<handle>KOSTE-ARIN</handle>
<lastName>Kosters</lastName>
<emails>
<email>markk@kosters.net</email>
<email>markk@bjmk.com</email>
</emails>
<resources termsOfUse="https://www.arin.net/whois_tou.html"
inaccuracyReportUrl="http://www.arin.net/public/whoisinaccuracy/index.xhtml">
<limitExceeded limit="256">false</limitExceeded>
</resources>
<phones>
<phone>
<number>+ 1-703-227-9870</number>
<type>
<description>Office</description>
<code>O</code>
</type>
</phone>
</phones>
<postalCode>20151</postalCode>
<comment>
<line number="0">I&#39;m really MAK21-ARIN</line>
</comment>
<iso3166-2>VA</iso3166-2>
<streetAddress>
<line number="0">3635 Concorde Parkway</line>
</streetAddress>
<updateDate>2015-05-26T11:36:55-04:00</updateDate>
</poc>

您的网络服务返回的内容可能看起来有些不同。或者,就像上面的 ARIN whois RWS 的情况一样,您可能有多种数据格式可供选择; XML 只是默认设置。我可以使用

请求纯文本响应
httpReq.Open "GET", "http://whois.arin.net/rest/poc/KOSTE-ARIN.txt", False

在这种情况下响应将包含

#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#


Name: Kosters, Mark
Handle: KOSTE-ARIN
Company: ARIN
Address: 3635 Concorde Parkway
City: Chantilly
StateProv: VA
PostalCode: 20151
Country: US
RegDate: 2009-10-02
Updated: 2015-05-26
Comment: I'm really MAK21-ARIN
Phone: +1-703-227-9870 (Office)
Email: markk@bjmk.com
Email: markk@kosters.net
Ref: http://whois.arin.net/rest/poc/KOSTE-ARIN
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#

关于api - 创建与基于 REST 的 API 的 Microsoft Access 数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32768235/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com