我試圖在 stackoverflow 上找到答案但無濟于事,所以我需要一些幫助:
我能夠輸入一個 URL azure 函式并讓它通過 body 物件/方法顯示結果。
我一直在嘗試通過 VBA 從 Azure 函式中檢索回傳值,但是當我這樣做時,我收到一條“內部錯誤”訊息。即使我將我從 VBA 創建的 URL 復制粘貼到地址欄中,也是一樣。
代碼中的Javascript有"return("Hello World!");" 用于測驗 responseText 但由于 HTTP 500 內部服務器錯誤,我似乎無法讓 VBA 甚至抓住它。
VBA 在構建 URL 字串的程序中做了什么,如果我將它輸入到地址欄本身會有所不同?
Azure 函式作為 API 運行,我只是執行 GET 方法來呼叫它并帶回計算。
任何幫助,將不勝感激。這是我關注的 VBA 代碼:
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 并調整引數,它在正文中成功回應。我似乎無法從 VBA 呼叫它來獲取回傳值。
我能夠在 Visual Studio Code 中在本地和 Azure 中運行它。 并且通過實際輸入 URL 并點擊“輸入”。但是在執行 GET 方法時,在 VBA 中構建 URL 似乎并不成功,因此,沒有 responseText。
再說一遍: VBA 正在做什么以不同的方式構造 URL,以至于無法從呼叫中獲取 responseText?和什么我需要做糾正它嗎?
uj5u.com熱心網友回復:
缺少&分隔查詢字串引數:
thisURL = "https://someazurefunction.net/api/somefunc"
thisURL = thisURL & "?name=" & ptc & "&assets=" & assets
也應該是 URL 編碼ptc和assets
如何在 Excel VBA 中對字串進行 URL 編碼?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/363801.html
標籤:javascript 擅长 vba 天蓝色
