无法获取参数以在 Azure Api 管理中正确重写 url
Cannot get params over to rewrite url properly in Azure Api Management
我正在尝试让 apim 重写...
https://apimpath/customers/1234
到
https://backendpath/api/customers/1234
失败了。尝试了一些东西,但它们似乎都无法识别 customerId。我错过了什么?
------更新------
尝试了下面的一些建议,但没有帮助。这是显示相同消息
的新 ui
尝试通过 api 添加它,并对其进行多种变体...
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: /*"
}
]
}
}
这似乎是一个错误。我也可以重新创建这个。
如果您使用参数创建操作,它会保存在某处。
更改它似乎不起作用,因为
正确的顺序是直接使用正确的参数名称创建操作。然后添加后端重写规则。
如果您看一下屏幕截图,您创建的原始操作是“/*”而不是“/{customerId}”
我在新 UI/Portal 中对此进行了测试。
- 我创建了一个操作“/{id}”,
- 添加了重写“/api/{id}”
- 测试了它并且有效
- 将操作重命名为“/{customerId}”
- 遇到以下错误:
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}
我正在尝试让 apim 重写...
https://apimpath/customers/1234
到
https://backendpath/api/customers/1234
失败了。尝试了一些东西,但它们似乎都无法识别 customerId。我错过了什么?
------更新------
尝试了下面的一些建议,但没有帮助。这是显示相同消息
的新 ui尝试通过 api 添加它,并对其进行多种变体...
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: /*"
}
]
}
}
这似乎是一个错误。我也可以重新创建这个。
如果您使用参数创建操作,它会保存在某处。 更改它似乎不起作用,因为
正确的顺序是直接使用正确的参数名称创建操作。然后添加后端重写规则。
如果您看一下屏幕截图,您创建的原始操作是“/*”而不是“/{customerId}”
我在新 UI/Portal 中对此进行了测试。
- 我创建了一个操作“/{id}”,
- 添加了重写“/api/{id}”
- 测试了它并且有效
- 将操作重命名为“/{customerId}”
- 遇到以下错误:
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}