I am trouble shooting an inbound 3rd party service and I want to log all inbound headers. As I dont know what headers I am receiving I cant use log analytics to capture headers.
I would like to use a mock response on APIM to print all inbound headers as a response message.
I have created the policy:
<policies>
<inbound>
<base />
<set-variable name="HostName" value="@{
string [] HostNameHeader;
context.Request.Headers.TryGetValue("Host", out HostNameHeader);
return HostNameHeader[0];
}" />
<return-response>
<set-status code="200" />
<set-body>"@{context.Variables["HostName"]}"</set-body>
</return-response>
<mock-response status-code="200" content-type="application/json" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
My response message is returning the text “@{context.Variables[“HostName”]}” rather than the the expected headers.