ai.https
请求
方法
| 描述
|
|---|---|
request(url, method, body, headers, ) (allowAutoRedirect) | 发出 HTTPS 请求。返回响应。
截至 2018.3,request(method) 支持
|
requestStream(url, 方法, 正文, 标头
适用于 2018.3 | 发出 HTTPS 流请求。返回响应。
|
authorizedRequest(url, method, body, headers) | 使用为启用了 OAuth 的 CCDS 生成的授权标头发出 https 请求。返回响应。
使用基础 OAuth 配置项详细信息以及数据源中的授权信息,为 https 请求生成授权标头。 自 2018.3 起,authorizedRequest(method) 支持
|
requestAuthorizedStream(url, method, body, headers)
适用于 2018.3 | 使用为启用了 OAuth 的 CCDS 生成的授权标头发出 HTTPS 流请求。返回响应。
使用基础 OAuth 配置条目详细信息以及数据源中的授权信息,为 https 流请求生成授权标头。 RequestAuthorizedStream(method) supports
|
示例
- 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); }