[英]How to make http request in Apigee JavaScript policy?
我正在使用 Apigee API 代理,并且在代理端点的 PreFlow 部分我必须发出 http 请求。 我创建了一个 JavaScript 策略,我尝试使用fetch
发出请求,但是当我调用端点时,响应是ReferenceError: "fetch" is not defined
。 有人有什么建议吗?
Apigee JavaScript 对象模型公开httpClient
对象。
更多细节可以在docs中找到。
我设置了一个稍后调用的变量,并像这样使用 httpClient 调用:
//===================================
//== Set Function to pass response ==
//===================================
function onComplete (response, error){
//== Check if HTTP request was successful ==
//==========================================
if(response){
context.setVariable("responsePayload1", response.content);
}
//== Set Error Variable is it fails ==
//====================================
else {
context.setVariable("example.error", "Whoops: "+error)
}}
//==================================
//== Set Variable to run function ==
//==================================
var calloutResponse = httpClient.get("http://yourwebsitename.com/your-call-uri", onComplete);
通过设置变量,它强制 JS 除了运行上述 function 之外还运行 httpClient.get 命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.