【问题标题】:How to make http request in Apigee JavaScript policy?如何在 Apigee JavaScript 策略中发出 http 请求?
【发布时间】:2022-11-18 04:10:43
【问题描述】:

我正在使用 Apigee API 代理,并且在 Proxy 端点的 PreFlow 部分我必须发出 http 请求。我创建了一个 JavaScript 策略,我尝试使用 fetch 发出请求,但是当我调用端点时,响应是 ReferenceError: "fetch" is not defined。有人有什么建议吗?

【问题讨论】:

    标签: apigee


    【解决方案1】:

    Apigee JavaScript 对象模型公开了 httpClient 对象。

    更多细节可以在docs 中找到。

    【讨论】:

      【解决方案2】:

      我设置了一个稍后调用的变量,并像这样使用 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 命令。

      【讨论】:

        猜你喜欢
        • 2018-09-28
        • 2014-09-22
        • 2016-08-09
        • 2021-10-26
        • 1970-01-01
        • 2023-01-10
        • 1970-01-01
        • 2021-09-29
        相关资源
        最近更新 更多