【问题标题】:Mulesoft can't find OPTIONS request listenerMulesoft 找不到 OPTIONS 请求侦听器
【发布时间】:2020-06-11 20:05:44
【问题描述】:

我在 Mulesoft 中创建了一个 API,我需要从 Angular 前端使用它。 GET 请求工作正常,但是当我尝试发送 POST/DELETE 请求时,它在发送 OPTIONS 请求时出错(响应没有 cors 标头,而 cors 设置正确)。当我在特定路由上添加我的一个端点以接受 OPTIONS 时,它工作正常。我可以以某种方式为在任何路由上发送的每个 OPTIONS 请求创建一个全局侦听器。 HTTP 连接器代码如下。

<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="8d79948b-c780-43eb-b7d1-41235210a0ff" basePath="/api" >
    <http:listener-connection host="localhost" port="8081" protocol="HTTP" />
    <http:listener-interceptors >
        <http:cors-interceptor >
            <http:origins >
                <http:origin url="http://localhost:4200" accessControlMaxAge="30000">
                <http:allowed-methods>
                    <http:method methodName="GET" />
                    <http:method methodName="POST" />
                    <http:method methodName="DELETE" />
                    <http:method methodName="OPTIONS" />
                  <http:method methodName="PUT" />
                </http:allowed-methods>
                <http:allowed-headers >
                  <http:header headerName="Content-Type" />
                  <http:header headerName="Access-Control-Allow-Headers" />
                  <http:header headerName="Access-Control-Allow-Origin" />
              </http:allowed-headers>
              <http:expose-headers />
            </http:origin>

            </http:origins>
        </http:cors-interceptor>
    </http:listener-interceptors>
</http:listener-config>

【问题讨论】:

    标签: anypoint-studio mulesoft anypoint-platform


    【解决方案1】:

    这是我的配置,需要添加expose headers:

    <http:listener-config name="agentportal-httpListenerConfig">
        <http:listener-connection host="0.0.0.0" port="8081" />
        <http:listener-interceptors >
            <http:cors-interceptor allowCredentials="false">
                <http:origins >
                    <http:origin url="http://localhost:4200" accessControlMaxAge="30000" >
                        <http:allowed-methods >
                            <http:method methodName="OPTIONS" />
                            <http:method methodName="GET" />
                            <http:method methodName="POST" />
                        </http:allowed-methods>
                        <http:allowed-headers >
                            <http:header headerName="Content-Type" />
                            <http:header headerName="Authorization" />
                            <http:header headerName="Accept" />
                        </http:allowed-headers>
                        <http:expose-headers >
                            <http:header headerName="Access-Control-Allow-Origin" />
                            <http:header headerName="Access-Control-Allow-Methods" />
                            <http:header headerName="Access-Control-Allow-Headers" />
                        </http:expose-headers>
                    </http:origin>
    
                </http:origins>
            </http:cors-interceptor>
        </http:listener-interceptors>
    </http:listener-config>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2020-08-11
      相关资源
      最近更新 更多