如何在调用后端之前在Azure API管理中添加自定义标头
我有一个在Azure上公开的RESTAPI。Azure Api曾经调用在后端调用WCF服务 首先,我需要将JSON请求转换为XML。此外,要调用SOAP服务,我需要添加如下自定义头:-如何在调用后端之前在Azure API管理中添加自定义标头,azure,azure-api-management,Azure,Azure Api Management,我有一个在Azure上公开的RESTAPI。Azure Api曾经调用在后端调用WCF服务 首先,我需要将JSON请求转换为XML。此外,要调用SOAP服务,我需要添加如下自定义头:- <s:Header> <AuthHeader xmlns="http://abc.security.service"> <UserID>UserID</UserID> <Token>T
<s:Header>
<AuthHeader xmlns="http://abc.security.service">
<UserID>UserID</UserID>
<Token>Token</Token>
</AuthHeader>
</s:Header>
用户ID
代币
如何添加一个“入站策略”,将请求转换为XML并注入自定义头
如果您有任何想法或建议,我们将不胜感激 有关此要求,请参考我的APIM中的政策
<policies>
<inbound>
<base />
<json-to-xml apply="always" />
<set-body>@{
string inBody = context.Request.Body.As<string>();
string requestBody = inBody.Replace("<Document>","").Replace("</Document>","");
string header = "<s:Header><AuthHeader xmlns=\"http://abc.security.service\"><UserID>UserID</UserID><Token>Token</Token></AuthHeader></s:Header>";
return header + requestBody;
}</set-body>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
@{
字符串inBody=context.Request.Body.As();
字符串requestBody=inBody.Replace(“,”).Replace(“,”);
string header=“UserIDToken”;
返回头+请求体;
}
请注意标题中的转义字符
,我们需要使用\“
而不是”