首页 > 解决方案 > 如何在 IIS ARR 响应中重写 API 内容

问题描述

主页加载后,我的 Web 应用程序进行了辅助 API 调用。此 API 调用包含带有 URL 的 XML 数据,这些数据也需要重写,但不会被重写。

来自 API 调用的 XML 响应中的 URL 都需要重写为与调用来自的外部域相同的域。

我尝试过使用前提条件<add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/xml" />和使用前提条件<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />

两者似乎都不起作用。

使用的配置如下:

<rule name="ReverseProxyOutboundRule1">
    <match filterByTags="None" pattern="^http(s)?://k2.denallix.com/(.*)" />
    <conditions>
    </conditions>
    <action type="Rewrite" value="https://k2.reverseproxy.com/{R:2}" />
</rule>
<preConditions>
    <preCondition name="ResponseIsHtml1">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/xml" />
    </preCondition>
</preConditions>

Failed Request Tracing 没有错误,但 GENERAL_RESPONSE_ENTITY_BUFFER 显示 XML 中的响应没有重写 URL。

多个实例<Data>https://k2.denallix.com/Runtime/Runtime/View/Authorization+view/?SN=408849_21</Data>

实际上应该重写为<Data>https://k2.reverseproxy.com/Runtime/Runtime/View/Authorization+view/?SN=408849_21</Data>

谢谢。

标签: xmlapiiisurl-rewritingarr

解决方案


推荐阅读