簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM