简体   繁体   English

如何在 Apigee JavaScript 策略中提出 http 请求?

[英]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?有人有什么建议吗?

Apigee JavaScript Object Model exposes httpClient object. Apigee JavaScript 对象模型公开httpClient对象。

More detail can be found in the docs .更多细节可以在docs中找到。

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.

相关问题 如何在JavaScript中获取所有Apigee请求标头? - How to get all Apigee request headers in JavaScript? 在Apigee中,如何访问JavaScript策略中的标注响应 - In Apigee, how can I access callout response in javascript policy 在Apigee中,如何为统计信息收集器策略要使用的Javascript中的变量分配值? - In Apigee, how to assign a value to a variable in Javascript to be used by the Statistics Collector policy? jsonPath在apigee JavaScript策略中不起作用 - jsonPath not working in apigee javascript policy 如何配置logstash以向APIGEE Analytics API发出请求? - How to configure logstash to make an request to APIGEE analytics API? 使用apigee的JavaScript策略时使用javascript中的alert() - alert() in javascript while using apigee's JavaScript policy 在Apigee中,如何使用AccessEntity策略以及稍后在Javascript中为开发人员获取自定义属性值? - In Apigee, how to get a custom attribute value for a developer using the AccessEntity policy and later in Javascript? Apigee中未定义NodeJS异步http请求ArrayBuffer - NodeJS async http request ArrayBuffer not defined in Apigee 如何在Apigee中签署SOAP请求 - How to sign SOAP request in Apigee 如何使 Apigee 4.23 (OPDK) 允许来自没有 ALLOW 标头的后端的 HTTP 405 响应? - How to make Apigee 4.23 (OPDK) allow HTTP 405 response from backend that doesn't have the ALLOW header?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM