你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Api Policy - Create Or Update
为 API 创建或更新策略配置。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/policies/policy?api-version=2024-05-01
URI 参数
名称 | 在 | 必需 | 类型 | 说明 |
---|---|---|---|---|
api
|
path | True |
string minLength: 1maxLength: 256 pattern: ^[^*#&+:<>?]+$ |
API 修订标识符。 当前 API 管理服务实例中必须是唯一的。 非当前修订有;rev=n 作为后缀,其中 n 是修订号。 |
policy
|
path | True |
策略的标识符。 |
|
resource
|
path | True |
string minLength: 1maxLength: 90 |
资源组的名称。 名称不区分大小写。 |
service
|
path | True |
string minLength: 1maxLength: 50 pattern: ^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$ |
API 管理服务的名称。 |
subscription
|
path | True |
string (uuid) |
目标订阅的 ID。 该值必须是 UUID。 |
api-version
|
query | True |
string minLength: 1 |
用于此作的 API 版本。 |
请求头
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
If-Match |
string |
实体的 ETag。 创建实体时不需要,但在更新实体时是必需的。 |
请求正文
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
properties.value | True |
string |
由格式定义的策略内容。 |
properties.format |
policyContent 的格式。 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
已成功更新租户的 API 策略配置。 标头 ETag: string |
|
201 Created |
已成功创建 Api 策略配置。 标头 ETag: string |
|
Other Status Codes |
描述作失败的原因的错误响应。 |
安全性
azure_auth
Azure Active Directory OAuth2 Flow。
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize
作用域
名称 | 说明 |
---|---|
user_impersonation | 模拟用户帐户 |
示例
Api |
Api |
ApiManagementCreateApiPolicy
示例请求
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy?api-version=2024-05-01
{
"properties": {
"format": "xml",
"value": "<policies> <inbound /> <backend> <forward-request /> </backend> <outbound /></policies>"
}
}
示例响应
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy",
"type": "Microsoft.ApiManagement/service/apis/policies",
"name": "policy",
"properties": {
"value": "<policies>\r\n <inbound />\r\n <backend>\r\n <forward-request />\r\n </backend>\r\n <outbound />\r\n</policies>"
}
}
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy",
"type": "Microsoft.ApiManagement/service/apis/policies",
"name": "policy",
"properties": {
"value": "<policies>\r\n <inbound />\r\n <backend>\r\n <forward-request />\r\n </backend>\r\n <outbound />\r\n</policies>"
}
}
ApiManagementCreateApiPolicyNonXmlEncoded
示例请求
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy?api-version=2024-05-01
{
"properties": {
"value": "<policies>\r\n <inbound>\r\n <base />\r\n <set-header name=\"newvalue\" exists-action=\"override\">\r\n <value>\"@(context.Request.Headers.FirstOrDefault(h => h.Ke==\"Via\"))\" </value>\r\n </set-header>\r\n </inbound>\r\n </policies>",
"format": "rawxml"
}
}
示例响应
{
"id": "/subscriptions/4c1a3bc6-89f9-46fe-a175-5d8984b25095/resourcegroups/Api-DF-West-US/providers/Microsoft.ApiManagement/service/samirmsiservice2/apis/echo-api/operations/create-resource/policies/policy",
"type": "Microsoft.ApiManagement/service/apis/operations/policies",
"name": "policy",
"properties": {
"value": "<policies>\r\n <inbound>\r\n <base />\r\n <set-header name=\"newvalue\" exists-action=\"override\">\r\n <value>\"@(context.Request.Headers.FirstOrDefault(h => h.Ke==\"Via\"))\" </value>\r\n </set-header>\r\n </inbound>\r\n</policies>"
}
}
{
"id": "/subscriptions/4c1a3bc6-89f9-46fe-a175-5d8984b25095/resourcegroups/Api-DF-West-US/providers/Microsoft.ApiManagement/service/samirmsiservice2/apis/echo-api/operations/create-resource/policies/policy",
"type": "Microsoft.ApiManagement/service/apis/operations/policies",
"name": "policy",
"properties": {
"value": "<policies>\r\n <inbound>\r\n <base />\r\n <set-header name=\"newvalue\" exists-action=\"override\">\r\n <value>\"@(context.Request.Headers.FirstOrDefault(h => h.Ke==\"Via\"))\" </value>\r\n </set-header>\r\n </inbound>\r\n</policies>"
}
}
定义
名称 | 说明 |
---|---|
Error |
资源管理错误附加信息。 |
Error |
错误详细信息。 |
Error |
错误响应 |
Policy |
policyContent 的格式。 |
Policy |
策略协定详细信息。 |
Policy |
策略的标识符。 |
ErrorAdditionalInfo
资源管理错误附加信息。
名称 | 类型 | 说明 |
---|---|---|
info |
object |
其他信息。 |
type |
string |
其他信息类型。 |
ErrorDetail
错误详细信息。
名称 | 类型 | 说明 |
---|---|---|
additionalInfo |
错误附加信息。 |
|
code |
string |
错误代码。 |
details |
错误详细信息。 |
|
message |
string |
错误消息。 |
target |
string |
错误目标。 |
ErrorResponse
错误响应
名称 | 类型 | 说明 |
---|---|---|
error |
错误对象。 |
PolicyContentFormat
policyContent 的格式。
值 | 说明 |
---|---|
rawxml |
内容是内联的,内容类型是非 XML 编码策略文档。 |
rawxml-link |
策略文档未进行 XML 编码,托管在可从 API 管理服务访问的 HTTP 终结点上。 |
xml |
内容是内联的,内容类型是 XML 文档。 |
xml-link |
策略 XML 文档托管在可从 API 管理服务访问的 HTTP 终结点上。 |
PolicyContract
策略协定详细信息。
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
id |
string |
资源的完全限定资源 ID。 Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} |
|
name |
string |
资源的名称 |
|
properties.format | xml |
policyContent 的格式。 |
|
properties.value |
string |
由格式定义的策略内容。 |
|
type |
string |
资源的类型。 例如“Microsoft.Compute/virtualMachines”或“Microsoft.Storage/storageAccounts” |
PolicyIdName
策略的标识符。
值 | 说明 |
---|---|
policy |