【发布时间】:2022-11-18 04:10:43
【问题描述】:
我正在使用 Apigee API 代理,并且在 Proxy 端点的 PreFlow 部分我必须发出 http 请求。我创建了一个 JavaScript 策略,我尝试使用 fetch 发出请求,但是当我调用端点时,响应是 ReferenceError: "fetch" is not defined。有人有什么建议吗?
【问题讨论】:
标签: apigee
我正在使用 Apigee API 代理,并且在 Proxy 端点的 PreFlow 部分我必须发出 http 请求。我创建了一个 JavaScript 策略,我尝试使用 fetch 发出请求,但是当我调用端点时,响应是 ReferenceError: "fetch" is not defined。有人有什么建议吗?
【问题讨论】:
标签: apigee
Apigee JavaScript 对象模型公开了 httpClient 对象。
更多细节可以在docs 中找到。
【讨论】:
我设置了一个稍后调用的变量,并像这样使用 httpClient 调用:
function onComplete (response, error){
//== Check if HTTP request was successful ==
//==========================================
if(response){
context.setVariable("responsePayload1", response.content);
} else {
context.setVariable("example.error", "Whoops: "+error)
}}
var calloutResponse = httpClient.get("http://yourwebsitename.com/your-call-uri", onComplete);
通过设置变量,它强制 JS 除了运行上述功能外还运行 httpClient.get 命令。
【讨论】: