0
votes

I'm pretty new to azure API management and I'm trying to check or print the HTTP request header "Host" of my API call in Azure API management with policies.

HTTP header response:

Request headers:

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

This is what I've tried so far:

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

Hope someone can help.

Thanks in advance!

1
Depends on how you define "print". APIM receives request, passes it to backend, received response, passes it to client. There is not much in a way to "print" anything other than to put it into response or a trace, which is collected only when requested. So what exactly do you want to do?Vitaliy Kurokhtin

1 Answers

1
votes

Try Policy expressions in Azure API Management

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

For more information refer below link:

API Management policy expressions