excel - Excel VBA graphQL http 请求“运行时错误 -2147012744 服务器返回了无效或无法识别的响应”
问题描述
我编写了 VBA 代码以通过 GraphQL API 检索 JSON 结果,但遇到运行时错误
-2147012744 服务器返回无效或无法识别的响应
我的 VBA 代码如下,我在 .send reqQueryAsBody 语句中遇到错误
Dim req As Object
Dim reqURL As String
Dim BearerToken As String
Dim JsonResult As String
'Declare Query related Dimensions
Dim reqQueryName As String
Dim reqvarName As String
Dim reqQueryAsBody As String
'Declare Json Dimensions
Dim JSONa, element, var As Object, rep As Variant, e As Variant, i As Variant
Dim sht As Worksheet
Set sht = ThisWorkbook.Worksheets("Main")
'To check whether Query is Typed or Not in provided space in Main Excel Sheet
If IsEmpty(sht.Range("reqQuery").value) = True Then
MsgBox "Kindly Type requested Query in Provided Space in Main Sheet", vbInformation, "Info"
sht.Range("reqQuery").Activate
Exit Sub
ElseIf IsEmpty(sht.Range("reqVariable").value) = True Then
MsgBox "Kindly Select requested variable in Provided Space in Main Sheet", vbInformation, "Info"
sht.Range("reqVariable").Activate
Exit Sub
Else
reqQueryName = sht.Range("reqQuery").value
reqvarName = sht.Range("reqVariable").value
BearerToken = "xxxxxxxxxxxx"
'html URL
reqURL = "http://tddrapi.trustfci.com/graphql"
Query Prepare Query as per Structure
reqQueryAsBody = "{""query"": { " & reqQueryName & "" & vbCrLf & _
" (" & vbCrLf & " offset:0, " & vbCrLf & _
" orderby: """ & reqvarName & """, " & vbCrLf & _
" order: ""asc"" " & vbCrLf & _
" ) " & vbCrLf & _
" {" & vbCrLf & _
" " & reqvarName & " " & vbCrLf & _
" }" & vbCrLf & _
" }" & vbCrLf & "}"
Debug.Print reqQueryAsBody
Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
With req
.Open "POST", reqURL, False
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Authorization", "Bearer " & BearerToken
.send reqQueryAsBody
End With
debug.print req.responseText
JsonResult = req.responseText
解决方案
首先,服务被停止了,不是吗。
`$ ping tddrapi.trustfci.com
PING tddrapi.trustfci.com (70.141.38.184) 56(84) bytes of data.
^C
--- tddrapi.trustfci.com ping statistics ---
8 packets transmitted, 0 received, 100% packet loss, time 7248ms`
推荐阅读
- ios - Swift 4 OutputStream 产生的输出多于输入
- kotlin - 如何使用 Gson 将继承的 Kotlin 数据类中的特定字段反序列化为字符串
- swift - Swift 正则表达式优化
- html - 如何在不将应用程序暴露在其他地方的情况下将服务器端 Shiny 应用程序嵌入到 JSP 页面中
- java - 抛出异常顺序
- rest - Firebase 数据库 REST 获取 orderBy 值和参数
- dart - 如何在 Flutter 中重新加载 FileImage
- mysql - 需要的mysql语句
- multithreading - 如何识别进程中每个线程的内存消耗?
- java - Javafx 特定文件夹的路径并选择在文本字段中输入的文件