2017-07-20 28 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,你還能重現這個問題嗎? –