2017-07-20 25 views
1

我试图让APIM采取重写......不能得到PARAMS到Azure中阿比管理正确重写URL

https://apimpath/customers/1234

https://backendpath/api/customers/1234

enter image description here

失败。尝试了几件事情,但他们似乎都不认可customerId。我错过了什么?

------更新-------

尝试下面的一些建议,并没有帮助。下面是该相同的消息

enter image description here

尝试添加它通过与这几个变化的API全新的UI ...

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

里面添加成功操作...

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> 

但上述请求失败,结果为...

{ 
    "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: /*" 
      } 
     ] 
    } 
} 
+0

似乎很奇怪。它看起来像你在做什么是正确的。尝试设置网址模板,将其保存,然后设置重写网址模板作为第二步。 –

+0

另外,您可能想尝试将其设置在Azure门户的新UI中。 –

+0

欣赏建议,但都无效。不知道有一个新的用户界面,但如果失败,同样的错误。将该截图添加到原始问题中。真的停留在这一个。 – sjdirect

回答

0

这似乎是一个错误。我也可以重新创建它。

如果使用参数创建操作,则会将其保存在某处。 更改它似乎并不奏效,因为

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

如果你看看截图,您创建的原始操作是“/ *”,而不是“/ {}客户ID”

我在新UI /门户网站测试这一点。

  • 我创建了一个操作 “/(编号)”,
  • 添加重写 “/ API /(编号)”
  • 测试它和它的工作
  • 改名操作“/ {客户ID }”
  • 遇到以下错误:

One or more fields contain incorrect values: Error in element 'rewrite-uri' on line 16, column 10: Only parameters specified in the original URL template can be used in the rewrite template. Original template is: /{id}

+1

此问题是apim系统中的一个错误。不知何故,删除操作并不会真正删除操作。您需要使用新名称创建新操作,或者仍然保留第一个URL映射并验证所有策略。谢谢Erik! – sjdirect

+0

如果我理解正确,那么您是说如果您为某个操作重命名URL模板并更改了模板参数名称,则它不会自动更新RewriteUrl中相应的模板参数。是对的吗? –

+0

它将无法更新rewrite-url中的参数,因为通常情况下可能有多个参数,并且不清楚重命名后哪个参数。我刚刚测试过,如果您在URL模板中将“/ {id}”变为“/ {customerId}”,并将重写URL模板更改为“/ api/{customerId}”,则可以正常工作。 @sjdirect,你还能重现这个问题吗? –