1

Using the send-request Policy in Azure APIM. Able to get the response and extract the Body. However, struggling with extracting the response headers ?

Here is the code I am using to send the request with the send-request policy in the inbound section, i need to acces the response header of my request then perform another request with this header.

<send-request mode="new" response-variable-name="cookieContext" timeout="20" ignore-error="true">
        <set-url>{{SOAPAPIURL}}</set-url>
        <set-method>POST</set-method>
        <set-header name="SOAPAction" exists-action="override">
            <value>"AuthenticationService"</value>
        </set-header>
        <set-header name="Content-Type" exists-action="override">
            <value>text/xml</value>
        </set-header>
        <set-body template="liquid">
            {{soapBodyXml}}
                </s:Body>
            </s:Envelope>
        </set-body>
    </send-request>
Ais Amin
  • 21
  • 4

1 Answers1

1

Hello i found the solution. So, you can access the body response of the send-request policy like this : <set-variable name="bodyResponse" value="@(((IResponse)context.Variables["cookieContext"]).Body.As<String>(preserveContent: true).ToString())" />

Also, you can acces the response header like this : <set-variable name="set-cookie" value="@(((IResponse)context.Variables["cookieContext"]).Headers.GetValueOrDefault("Set-Cookie").Split(';')[0])" />

Ais Amin
  • 21
  • 4