跳至主要內容
Adaptive Planning
上次更新時間 :2023-06-23
ai.https

ai.https

​要求

方法
說明
request(url, method, body, headers)
發出 HTTPS 要求。傳回回應。
自 2018.3 起,request(method) 支援
  • GET︰擷取資料。
  • POST︰將資料提交至指定的資源。
  • PUT︰建立/取代指定的資源。
  • PATCH︰將部分修改套用至資源。
requestStream(url, method, body, headers
適用於 2018.3
發出 HTTPS 串流要求。傳回回應。
  • GET︰擷取資料。
  • POST︰將資料提交至指定的資源。
  • PUT︰建立/取代指定的資源。
  • PATCH︰將部分修改套用至資源。
authorizedRequest(url, method, body, headers)
發出 https 要求,並為已啟用 OAuth 的 CCDS 產生授權標頭。傳回回應。
使用基礎 OAuth 配置項目詳細資料以及資料來源中的授權資訊,以產生 https 要求的授權標頭。
自 2018.3 起,authorizedRequest(method) 支援
  • GET︰擷取資料。
  • POST︰將資料提交至指定的資源。
  • PUT︰建立/取代指定的資源。
  • PATCH︰將部分修改套用至資源。
requestAuthorizedStream(url, method, body, headers)
適用於 2018.3
發出 HTTPS 串流要求,並為已啟用 OAuth 的 CCDS 產生授權標頭。傳回回應。
使用基礎 OAuth 配置項目詳細資料以及資料來源中的授權資訊,以產生 https 串流要求的授權標頭。
RequestAuthorizedStream(method) 支援
  • GET︰擷取資料。
  • POST︰將資料提交至指定的資源。
  • PUT︰建立/取代指定的資源。
  • PATCH︰將部分修改套用至資源。

回覆

方法
說明
getHttpCode()
傳回回應的 HTTP 代碼。如需 HTTP 回應代碼的完整清單, 請按此處
getHeaders()
傳回回應標頭。
getBody()
傳回回應內容。

範例

ai.https.request
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/get?foo1=bar1&foo2=bar2'; var method = 'GET'; var body = ''; var headers = null; //ai.https.request var response = ai.https.request(URL, method, body, headers); var responseCode = response.getHttpCode(); if (responseCode == 200) { ai.log.logInfo('Test Connection Succeeded','Response code was 200'); return true; } else{ ai.log.logInfo('Test Connection Failed','Response code was not 200'); return false; } }
ai.https.requestStream
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/get?foo1=bar1&foo2=bar2'; var method = 'GET'; var body = ''; var headers = null; var response = ai.https.requestStream(URL, method, body, headers); return true; }
ai.https.authorizedRequest
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/basic-auth'; var method = 'GET'; var username='postman'; var pwd='password'; var body = '<username>'+username+'</username><password>'+pwd+'</password>'; var headers = {'Authorization': 'Basic cG9zdG1hbjpwYXNzd29yZA=='}; var response = ai.https.authorizedRequest(URL, method, body, headers); var responseCode = response.getHttpCode(); ai.log.logInfo(responseCode); if (responseCode == 200) { ai.log.logInfo('Test Connection Succeeded','Response code was 200'); var responseBody = response.getBody(); ai.log.logInfo(responseBody); //{"authenticated":true} return true; } else{ ai.log.logInfo('Test Connection Failed','Response code was not 200'); return false; } }
ai.requestAuthorizedStream
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/basic-auth'; var method = 'GET'; var username='postman'; var pwd='password'; var body = '<username>'+username+'</username><password>'+pwd+'</password>'; var headers = {'Authorization': 'Basic cG9zdG1hbjpwYXNzd29yZA=='}; var response = ai.https.requestAuthorizedStream(URL, method, body, headers); }