Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Proxy Apigee-如何重定向到其他资源_Proxy_Apigee - Fatal编程技术网

Proxy Apigee-如何重定向到其他资源

Proxy Apigee-如何重定向到其他资源,proxy,apigee,Proxy,Apigee,我用Apigee创建了一个API代理,它可以正常工作。但是,我想更改资源名称 目前,我拥有以下资源: /collection/{Id}/products重定向到/collection/{Id}/products 我想重命名代理资源,如下所示: /collection/{Id}/apps重定向到/collection/{Id}/products 使用Apigee的最佳方式是什么 干杯, Chavdar如果您想将/collection/{id}/apps的请求代理到/collection/{id}/

我用Apigee创建了一个API代理,它可以正常工作。但是,我想更改资源名称

目前,我拥有以下资源:

/collection/{Id}/product
s重定向到
/collection/{Id}/products

我想重命名代理资源,如下所示:

/collection/{Id}/apps
重定向到
/collection/{Id}/products

使用Apigee的最佳方式是什么

干杯,
Chavdar

如果您想将
/collection/{id}/apps
的请求代理到
/collection/{id}/products
,请使用以下代码片段向目标请求添加JavaScript策略:

var collection_id = 10; //you should get this using context.getVariable()
var path = '/collection/' + collection_id + '/products'; //new path
var current_target_url = context.getVariable('target.url'); //get the existing target url
context.setVariable('target.copy.pathsuffix', false); //tell apigee to not copy the path over to the target
context.setVariable('debug.js.path', current_target_url + path); //this line is only for seeing the value in the trace tool
context.setVariable('target.url', current_target_url + path); //set the new path

您现有的xml是什么?这是在哪个端点(代理或目标)上?请澄清“重定向”是什么意思。是否要发回
位置
标头,或者您正在尝试代理到目标上的其他路径?我正在尝试代理到其他目标。谢谢试过这个。看起来这是一个有效的方法。唯一的问题是,这会将所有资源重定向到产品,而不仅仅是应用程序。我在代理请求中尝试过这样做:var collection_id=1;//您应该使用context.getVariable()var path='/collection/'+collection_id+'/products'来获取此信息//新路径var current_request_path=context.getVariable('request.path')//获取现有的请求路径context.setVariable('request.path',path);//设置新路径这不起作用。。有什么想法吗?你需要在目标上设置新的URL,因为这是请求的目的地。您可以用一个条件包装代码:
if(context.getVariable('proxy.pathsuffix')==“/collection/{id}/apps”){…}
。或者,将相同的逻辑添加到JavaScript的