ai.https
要求
方法
| 說明
|
|---|---|
request(url, method, body, headers) | 發出 HTTPS 要求。傳回回應。 自 2018.3 起,request(method) 支援
|
requestStream(url, method, body, headers 適用於 2018.3 | 發出 HTTPS 串流要求。傳回回應。
|
authorizedRequest(url, method, body, headers) | 發出 https 要求,並為已啟用 OAuth 的 CCDS 產生授權標頭。傳回回應。 使用基礎 OAuth 配置項目詳細資料以及資料來源中的授權資訊,以產生 https 要求的授權標頭。 自 2018.3 起,authorizedRequest(method) 支援
|
requestAuthorizedStream(url, method, body, headers) 適用於 2018.3 | 發出 HTTPS 串流要求,並為已啟用 OAuth 的 CCDS 產生授權標頭。傳回回應。 使用基礎 OAuth 配置項目詳細資料以及資料來源中的授權資訊,以產生 https 串流要求的授權標頭。 RequestAuthorizedStream(method) 支援
|
範例
- 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); }