javascript - 如何用VBA构造URL?

标签 javascript excel vba azure

我能够输入 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 编码 ptcassets

How can I URL encode a string in Excel VBA?

关于javascript - 如何用VBA构造URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70070522/

相关文章:

excel - 如何修复从 Access 内部关闭 Excel

javascript - IE 的 CSS 悬停属性替代方案

javascript - 在javascript中的if子句中返回一个值

Excel 公式简单除以 2 个单元格,使用 =+

excel - 使用 VBA 和 selenium 抓取时从部分 id 中获取全部值(value)

vba - 使用 Excel VBA 添加 Powerpoint 标题幻灯片

excel - 将 vba 函数应用到按钮正上方的单元格

javascript - 如何使用 JavaScript 验证联系表单?

javascript - 算法得到的数组总和,小于一个限制

excel - 允许 Access 用户选择 Excel 工作表进行链接