如何在Azure API管理中打印HTTP请求标头元素?

问题描述 投票:0回答:1

我对azure API管理很新,我正在尝试使用策略检查或打印Azure API管理中API调用的HTTP请求标头“Host”。

HTTP标头响应:

请求标头:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,nl;q=0.6
Cache-Control: max-age=0
Cookie: __utma=124807636.1965218888.1554190818.1554190818.1554190818.1; 
__utmc=124807636; __utmz=124807636.1554190818.1.1.utmcsr=google|utmccn= 
(organic)|utmcmd=organic|utmctr=(not%20provided); __utmt=1; 
__utmb=124807636.4.10.1554190818
Host: api.openweathermap.org
Proxy-Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36

这是我到目前为止所尝试的:

<policies>
<inbound>
    <check-header name="Host" failed-check-httpcode="401" failed-check-error-message="Not JSON" ignore-case="false">
        <value>api.openweathermap.org</value>
    </check-header>
    <base />
</inbound>
<backend>
    <base />
</backend>
<outbound>
    <base />
</outbound>
<on-error>
    <base />
</on-error>

希望有人能提供帮助。

提前致谢!

azure api validation http-headers azure-api-management
1个回答
0
投票

尝试在Azure API Management中使用策略表达式

@(context.Request.Headers.TryGetValue("Host", out value))

有关更多信息,请参阅以下链接

API Management policy expressions

© www.soinside.com 2019 - 2024. All rights reserved.