WSO2 EI从Angular客户端请求时发出预检请求CORS错误 [英] WSO2 EI giving preflight request CORS error while requesting from Angular client

查看:48
本文介绍了WSO2 EI从Angular客户端请求时发出预检请求CORS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angle Client调用wso2中的rest api,该api是从不是直接构建为api的数据服务中公开的,并且还尝试了堆栈溢出和wso2文档中提供的许多解决方案,没有任何帮助.

I am using angular client to call a rest api in wso2 which is exposed from a data service not directly built as an api and also tried many solutions provided in stack overflow and also wso2 documentation , nothing helps.

推荐答案

对于预检中的OPTIONS请求,WSO2 Enterprise Integrator(EI)的行为取决于API的实现.

With regard to OPTIONS requests in the preflight, the WSO2 Enterprise Integrator (EI) behaves as follows depending on the implementation of the API.

  1. 如果我们已将OPTIONS定义为一种资源方法,则EI会将请求发送到后端服务以收集信息.
  2. 如果我们尚未将OPTIONS定义为资源方法,则EI仅使用允许的方法以"Allow"标头进行回复,而无需进一步将请求发送给服务.

为了允许上述API满足跨域请求,请在API中包含以下资源.

In order to allow the above API to cater cross-origin requests please include the following resource in the API.

<resource methods="OPTIONS" uri-template="/*">
      <inSequence>
         <property name="Access-Control-Request-Headers" value="authorization,content-type" scope="transport"/>
         <property name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" scope="transport"/>
         <property name="Access-Control-Allow-Headers" value="*" scope="transport" type="STRING"/>
         <property name="Access-Control-Allow-Origin" value="*" scope="transport"/>
         <property name="RESPONSE" value="true" scope="default" type="STRING"/>
         <respond/>
      </inSequence>
</resource>

请注意,上面的示例设置了允许所有来源和所有标头的属性,您可以根据需要配置上述属性.除了上面的通配符("*")之外,还可以使用特定的值,包括以下受限制的原始值.

Please note that the above sample is set with the properties to allow all origins and all headers and you can configure the above properties according to your requirement. Instead of the above wildcards ("*") it's possible to use specific values including the following origin value which has been restricted.

这篇关于WSO2 EI从Angular客户端请求时发出预检请求CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆