首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Azure Api管理中正确重写url

无法在Azure Api管理中正确重写url
EN

Stack Overflow用户
提问于 2017-07-20 00:22:27
回答 1查看 3.5K关注 0票数 2

我想让apim重写..。

https://apimpath/customers/1234

https://backendpath/api/customers/1234

但失败了。尝试了一些东西,但它们似乎都不认识customerId。我遗漏了什么?

------Update-------

尝试了下面的一些建议,但没有帮助。下面是显示相同消息的新ui

尝试通过api添加它的几个变体。

代码语言:javascript
复制
PUT {{url}}/apis/customers/operations/GET?api-version=2016-7-7
{
  "name": "GET",
  "method": "GET",
  "urlTemplate": "/{customerId}",
  "templateParameters": [
    {"name": "customerId", "type": "string"}
    ],
  "policies": null
}

成功地增加了手术..。

代码语言:javascript
复制
PUT {{url}}/apis/customers/operations/GET/policy/?api-version=2016-7-7
<policies>
    <inbound>
        <base/>
        <rewrite-uri template="/api/customers/{customerId}"/>
    </inbound>
    <outbound>
        <base/>
    </outbound>
</policies>

但是上面的请求失败了。

代码语言:javascript
复制
{
    "error": {
        "code": "ValidationError",
        "message": "One or more fields contain incorrect values:",
        "details": [
            {
                "code": "ValidationError",
                "target": "rewrite-uri",
                "message": "Error in element 'rewrite-uri' on line 4, column 10: Only parameters specified in the original URL template can be used in the rewrite template. Original template is: /*"
            }
        ]
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-21 12:17:13

这好像是个虫子。我也能重现这一切。

如果使用参数创建操作,则该操作将保存在某个地方。改变它似乎行不通,因为

正确的顺序是使用正确的参数名称直接创建操作。然后添加后端重写规则。

如果您查看屏幕截图,您创建的原始操作是"/*“,而不是"/{customerId}”。

我在新的UI/Portal中测试了这一点。

  • 创建了一个操作"/{id}",
  • 添加重写"/api/{id}“
  • 测试了它,它起了作用
  • 将操作重命名为"/{customerId}“
  • 遇到以下错误:

一个或多个字段包含不正确的值:第16行中的元素‘re写-uri’中的错误,第10列:只有在原始URL模板中指定的参数才能在重写模板中使用。原始模板为: /{id}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45203137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档