Cors 交叉原点(驼峰路线和angularjs)
您好,我正在尝试使用apache camel为angularjs提供服务,但出现错误: 如果使用restConfiguration,则请求的资源上不存在“Access Control Allow Origin”标头。出毛病了 在我的蓝图中,我启用了CRO并设置了如下属性头,但不起作用:Cors 交叉原点(驼峰路线和angularjs),cors,apache-camel,Cors,Apache Camel,您好,我正在尝试使用apache camel为angularjs提供服务,但出现错误: 如果使用restConfiguration,则请求的资源上不存在“Access Control Allow Origin”标头。出毛病了 在我的蓝图中,我启用了CRO并设置了如下属性头,但不起作用: <restConfiguration bindingMode="json" component="jetty" enableCORS="true"> <dataFormatPropert
<restConfiguration bindingMode="json" component="jetty" enableCORS="true">
<dataFormatProperty key="prettyPrint" value="true" />
<corsHeaders key="Access-Control-Allow-Methods" value="GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH"></corsHeaders>
<corsHeaders key="Access-Control-Allow-Origin" value="*"></corsHeaders>
<corsHeaders key="Access-Control-Allow-Headers" value="Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"></corsHeaders>
<corsHeaders key="Access-Control-Max-Age" value="3600"></corsHeaders>
</restConfiguration>
如果我删除rest配置并像下面那样设置标题,我就没有错误
<route id="jetty" streamCache="true">
<from uri="jetty:http://0.0.0.0:9100/ifom/miki?matchOnUriPrefix=true"/>
<to uri="jetty:http://localhost:8080/om/miki?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
<log message="jetty-done header: ${headers}"/>
<setHeader headerName="Access-Control-Allow-Headers"><constant>X-Auth-Token, Content-Type</constant></setHeader>
<setHeader headerName="Access-Control-Allow-Origin"><constant>*</constant></setHeader>
<setHeader headerName="Access-Control-Allow-Methods"><constant>OPTIONS, POST</constant></setHeader>
</route>
X-Auth-Token,内容类型
*
选项,邮政
为什么rest配置不起作用?
Thank's我终于解决了这个问题,在Camel和AngularJs上为访问控制允许头和访问控制请求头设置了相同的值 AngularJs:
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Request-Headers': 'access-control-allow-methods,access-control-allow-origin,authorization,content-type',
'Access-Control-Allow-Headers': 'access-control-allow-methods,access-control-allow-origin,authorization,content-type',
'Access-Control-Allow-Methods': 'GET, DELETE, POST, OPTIONS, PUT',
}
骆驼:
.setHeader("Access-Control-Allow-Origin", constant("*"))
.setHeader("Access-Control-Allow-Headers", constant("access-control-allow-methods,access-control-allow-origin,authorization,content-type"))
.setHeader("Access-Control-Allow-Methods", constant("GET, DELETE, POST, OPTIONS, PUT"))