[英]How to make http request in Apigee JavaScript policy?
I am using Apigee API proxy and in the PreFlow part of the Proxy endpoint I have to make a http request.我正在使用 Apigee API 代理,并且在代理端点的 PreFlow 部分我必须发出 http 请求。 I created a JavaScript policy, where I tried using
fetch
to make the request, but when I call the endpoint, the response is ReferenceError: "fetch" is not defined
.我创建了一个 JavaScript 策略,我尝试使用
fetch
发出请求,但是当我调用端点时,响应是ReferenceError: "fetch" is not defined
。 Does anybody have any suggestions what could work?有人有什么建议吗?
I set a Variable to be called later and used the httpClient call like so:我设置了一个稍后调用的变量,并像这样使用 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);
By setting the variable it forces the JS to run the httpClient.get command in addition to running the above function.通过设置变量,它强制 JS 除了运行上述 function 之外还运行 httpClient.get 命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.