【问题标题】:How can i get the headers from a response of a <send-request> policy in Azure APIM Policy?如何从 Azure APIM 策略中的 <send-request> 策略的响应中获取标头?
【发布时间】:2022-08-16 19:09:19
【问题描述】:

在 Azure APIM 中使用发送请求策略。能够得到响应并提取 Body。但是,努力提取响应标题?

这是我用来发送请求的代码发送请求在入站部分的策略中,我需要访问我的请求的响应标头,然后使用此标头执行另一个请求。

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

    标签: c# .net azure apim


    【解决方案1】:

    您好,我找到了解决方案。因此,您可以访问发送请求像这样的政策:&lt;set-variable name="bodyResponse" value="@(((IResponse)context.Variables["cookieContext"]).Body.As&lt;String&gt;(preserveContent: true).ToString())" /&gt;

    此外,您可以像这样访问响应标头:&lt;set-variable name="set-cookie" value="@(((IResponse)context.Variables["cookieContext"]).Headers.GetValueOrDefault("Set-Cookie").Split(';')[0])" /&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 2020-10-29
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      相关资源
      最近更新 更多