azure - 为什么无法访问 Azure API 管理策略中的内容类型?

标签 azure azure-api-management

作为入站请求的一部分,我想评估数据已发布的格式,以便我可以从一种格式转换为另一种格式。使用我试图获取内容类型;

string contentType = context.Request.Headers.GetValueOrDefault("Content-Type", "text/plain");

无论我在请求中设置什么内容类型,我都会获得默认值(文本/纯文本)。我记录了 header 以查看正在设置的内容,看来入站策略确实获取了 Content-Type header 。奇怪的是你可以设置但不能检索它。

如何确定发送的格式是什么?

最佳答案

它正在使用您提供的代码:

内容类型:application\json enter image description here 完整政策:

<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/

相关文章:

azure - 使用 Azure 事件中心的 Spark Streaming

Azure APIM - 如何请求/发布。我想阻止某些字符并允许少数字符?

Azure API 管理服务更新 CORS 以允许选项

azure - 如何创建Azure Devops的数组变量

具有多个客户端的 Azure APIM 和 oAuth 2.0

azure - 当Azure API管理和Web应用程序使用客户端证书身份验证时,如何支持大请求?

azure - 使用 API 管理服务及其 API 的 ARM 模板进行部署时出现问题

azure - 在 asp.net core 和 Angular 应用程序中处理过期的 Azure AD session

Azure 诊断设置 - 类别组

azure - 使用 Azure 函数绑定(bind)返回容器中的 Blob 列表