【发布时间】:2018-08-13 13:24:27
【问题描述】:
我在使用其余 API 将 JSON 数据发送到 firebase 数据库时遇到问题,数据已发送,但无法解析。例如,如果我在 Windows 的命令提示符中使用此 curl 命令:
curl -X PUT -d "{\"lastName\":\"Jones\",\"firstName\":\"Bubba\"}" https://<database-name>.firebaseio.com/rest/test/.json
然而,当使用以下 VBA 代码时:
Sub PUSHhttpRequestTest() 'Doesn't Work!!
Dim sc As Object
Set sc = CreateObject("ScriptControl")
sc.Language = "JScript"
Dim strURL As String: strURL = "https://<database-name>.firebaseio.com/rest/.json"
Dim strRequest
strRequest = """{\""lastName\"":\""Jones\"",\""firstName\"":\""Bubba\""}"""
Dim XMLhttp: Set XMLhttp = CreateObject("msxml2.xmlhttp")
Dim response As String
Debug.Print strRequest
XMLhttp.Open "PUT", strURL, False
XMLhttp.setrequestheader "Content-Type", "application/json;charset=UTF-8"
XMLhttp.sEnd strRequest
response = XMLhttp.responseText
Debug.Print response
End Sub
这会发送完全相同的字符串化 JSON,并将其添加到 Firebase 数据库,但是 JSON 字符串不会被解析:
我尝试了不同的内容类型和 JSON 字符串的变体,但似乎没有任何效果。谁能解释我如何让 VBA 脚本发送 Firebase 将解析的数据?
谢谢
【问题讨论】:
标签: json excel firebase firebase-realtime-database