作为入站请求的一部分,我想评估数据已发布的格式,以便我可以从一种格式转换为另一种格式。使用我试图获取内容类型;
string contentType = context.Request.Headers.GetValueOrDefault("Content-Type", "text/plain");
无论我在请求中设置什么内容类型,我都会获得默认值(文本/纯文本)。我记录了 header 以查看正在设置的内容,看来入站策略确实获取了 Content-Type header 。奇怪的是你可以设置但不能检索它。
如何确定发送的格式是什么?
最佳答案
它正在使用您提供的代码:
<policies>
<inbound>
<base />
<set-body template="none">@{
string contentType = context.Request.Headers.GetValueOrDefault("Content-Type", "text/plain");
return contentType;
}</set-body>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
关于azure - 为什么无法访问 Azure API 管理策略中的内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42439748/