我正在嘗試通過 VPN 中的 Gitlab 的 Google App Script 運行以下代碼。
VPN 已連接,我可以在 Curl Command、Browser 和 Postman 上獲得回應,但 Google App 腳本出錯。
this._url = "https://<url access on vpn and vpn is on>/api/v4/projects/1048/repository/compare?to=release/1.209.0&from=release/1.208.0"; this.payloadData = null;
this.fetchArgs = { contentType: "application/json", headers: { "Authorization": "Bearer <mytoken-accesible on Postmand and Curl>" }, muteHttpExceptions: true, method: methodType, }
try { this.responseData = UrlFetchApp.fetch(this._url, this.fetchArgs); this.responseCode = this.responseData.getResponseCode(); } catch (e) { console.log(e); }
回應始終如下
{ [Exception: Bad request: https://<baseURL>/api/v4/projects/1048/repository/compare?to=release/1.209.0&from=release/1.208.0] name: 'Exception' }
uj5u.com熱心網友回復:
如果您需要 VPN 來訪問鏈接,并且您可以使用 Postman、curl 和瀏覽器訪問它,但應用程式腳本沒有,那是因為所有這 3 個都在本地訪問 URL,因此他們可以使用 VPN 訪問它。
另一方面,Apps Script 遠程執行此操作(它們在谷歌服務器上運行),因此,您在沒有任何 VPN 的情況下訪問 URL,從而導致錯誤請求問題。
據說您可以使用SDC來解決這些問題,但它已被棄用。
參考:
- Apps 腳本、SQL DB 和 VPN
- Google 作業表上的代碼是在本地運行還是在 Google 服務器上運行?- UrlFetchApp 回傳空
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/449479.html
