【发布时间】:2019-06-17 20:14:27
【问题描述】:
我最近开始使用 apigee 代理。请不要阻止我。 我正在使用邮递员将数据发布到代理中。 我已经分配了一个提取策略来从 json 数据中提取一些值,例如 速度、纬度、经度等 然后我根据客户要求使用分配策略将速度转换为 gpsspeed 等。 之后,我使用 javascript 策略输出速度是否高于 > 50,然后是高或低。 我举一个数据的例子。 现在我想将结果数据转发到另一个 api。也许任何 apigee 为测试目的提供的东西。我想查看结果 api 中的数据。 我使用服务调用策略将数据发送到另一个 url。 我附上政策。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ServiceCallout-GeocodingRequest1">
<DisplayName>Inline request message</DisplayName>
<Request variable="callAnotherService">
<Set>
<Payload contentType="application/json">
{response.content} // reading data from javascript policy
</Payload>
</Set>
</Request>
<Response>CalloutResponse</Response>
<Timeout>30000</Timeout>
<HTTPTargetConnection>
<URL>http://httpbin.org/anything</URL>
</HTTPTargetConnection>
我在它之前附加了一个javascript策略。 我附上政策。
var content = context.getVariable("response.content") //read the response
content = JSON.parse(content); //parse into an object
if (content.speed > 50) { //apply the condition
content.speed = "high";
}
else {
content.speed = "low";
}
context.setVariable("response.content", JSON.stringify(content)); //set it
back on the response
谁能帮助我如何将数据转发到另一个 api?我的程序对吗?从java脚本策略中提取变量的程序对吗?请指导我。
【问题讨论】:
-
您确定您的javascript策略中的对象“response.content”在您将值设置回它后不为空
-
它不是空的..