我能够输入 URL azure 函数并让它通过主体对象/方法显示结果。
我一直在尝试通过 VBA 从 Azure 函数检索返回。
我收到“内部错误”消息。
当我将从 VBA 创建的 URL 复制到地址栏中时,同样的事情。
代码中的Javascript有“return("Hello World!");”用于测试responseText,但由于 HTTP 500 内部服务器错误,我什至无法让 VBA 抓取它。
Azure 函数作为 API 运行,我正在执行 GET 方法来调用它并返回计算结果。
Dim xmlhttpb As New MSXML2.XMLHTTP60
Dim resString As String
Dim thisURL As String
'example URL
thisURL = "https://someazurefunction.net/api/somefunc"
thisURL = thisURL & "?name=" & ptc & "assets=" & assets & ""
'I have also constructed it in one line
xmlhttpb.Open "GET", thisURL, False
xmlhttpb.Send
Debug.Print xmlhttpb.StatusText 'This returns an Internal Server Error
resString = xmlhttpb.responseText
' resString, when printed, is absolutely nothing, not even a "Null" or "Empty" due to the Internal Server error
作为复习,我可以输入 URL 并调整参数,它会在正文中成功响应。
我可以在 Visual Studio Code 中从 Azure 本地运行它,只需输入 URL 并按“回车”即可。
执行 GET 方法时,在 VBA 中构造 URL 似乎不成功,因此没有响应文本。
最佳答案
缺少 &
来分隔查询字符串参数:
thisURL = "https://someazurefunction.net/api/somefunc"
thisURL = thisURL & "?name=" & ptc & "&assets=" & assets
可能还应该是 URL 编码 ptc
和 assets
关于javascript - 如何用VBA构造URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70070522/