跳至主要内容
Adaptive Planning
上次更新时间 :2023-06-23
ai.https

ai.https

请求

方法
描述
request(url, method, body, headers, ) (allowAutoRedirect)
发出 HTTPS 请求。返回响应。
截至 2018.3,request(method) 支持
  • GET:检索数据。
  • POST:将数据提交到指定的资源。
  • PUT:创建/替换指定的资源。
  • PATCH:将部分修改应用于资源。
requestStream(url, 方法, 正文, 标头
适用于 2018.3
发出 HTTPS 流请求。返回响应。
  • GET:检索数据。
  • POST:将数据提交到指定的资源。
  • PUT:创建/替换指定的资源。
  • PATCH:将部分修改应用于资源。
authorizedRequest(url, method, body, headers)
使用为启用了 OAuth 的 CCDS 生成的授权标头发出 https 请求。返回响应。
使用基础 OAuth 配置项详细信息以及数据源中的授权信息,为 https 请求生成授权标头。
自 2018.3 起,authorizedRequest(method) 支持
  • GET:检索数据。
  • POST:将数据提交到指定的资源。
  • PUT:创建/替换指定的资源。
  • PATCH:将部分修改应用于资源。
requestAuthorizedStream(url, method, body, headers)
适用于 2018.3
使用为启用了 OAuth 的 CCDS 生成的授权标头发出 HTTPS 流请求。返回响应。
使用基础 OAuth 配置条目详细信息以及数据源中的授权信息,为 https 流请求生成授权标头。
RequestAuthorizedStream(method) supports
  • 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); }