Rest camel的Cors配置
我有一个对Rest Web服务的AJAX请求,其中有一个自定义标题“login” 以下是我的rest配置:Rest camel的Cors配置,rest,cors,apache-camel,Rest,Cors,Apache Camel,我有一个对Rest Web服务的AJAX请求,其中有一个自定义标题“login” 以下是我的rest配置: restConfiguration() .component("netty4-http") .bindingMode(RestBindingMode.json) .dataFormatProperty("prettyPrint", "true") .enableCORS(true) .corsAllowCredentials(true) .corsHeaderProperty("Acces
restConfiguration()
.component("netty4-http")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.enableCORS(true)
.corsAllowCredentials(true)
.corsHeaderProperty("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, login")
.contextPath(contextPath).host(host).port(port);
我收到了200个选项飞行前请求响应,但“登录”标题不是访问控制允许标题,我的浏览器从未发送实际请求
此外,我还没有在我的cors路线中进行任何配置
这是我的请求头
用户代理:Mozilla/5.0(Windows NT 10.0;Win64;x64;rv:58.0)
Gecko/20100101 Firefox/58.0
接受:
text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
接受语言:fr,fr;q=0.8,在美国;q=0.5,en;q=0.3
接受编码:gzip,deflate
访问控制请求方法:GET
访问控制请求头:登录
来源:
DNT:1
连接:保持活力
和响应头:
内容长度:0
接受:
text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
接受编码:gzip,deflate
接受语言:fr,fr;q=0.8,在美国;q=0.5,en;q=0.3
访问控制允许凭据:true
访问控制允许标头:来源、接受、X请求、带、,
内容类型、访问控制请求方法、,
访问控制请求头
访问控制允许方法:GET、HEAD、POST、PUT、DELETE、TRACE、,
选项、连接、补丁
访问控制允许来源:
访问控制最大年龄:3600
访问控制请求头:登录
访问控制请求方法:GET
面包屑标:ID-resitt-ws-1521624297667-0-6
DNT:1
来源:
用户代理:Mozilla/5.0(Windows NT 10.0;Win64;x64;rv:58.0)
Gecko/20100101 Firefox/58.0
连接:保持活动(modifié)
我觉得我的cors配置对我的情况没有任何改变。我们找到了一个答案,
.enableCORS(true)
必须放在.contextPath(contextPath).host(host).port(port)
行之后
像这样
restConfiguration()
.component("netty4-http")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.contextPath(contextPath).host(host).port(port)
.enableCORS(true)
.corsAllowCredentials(true)
.corsHeaderProperty("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, login");
我们找到了一个答案,
.enableCORS(true)
必须放在.contextPath(contextPath).host(host).port(port)
行之后
像这样
restConfiguration()
.component("netty4-http")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.contextPath(contextPath).host(host).port(port)
.enableCORS(true)
.corsAllowCredentials(true)
.corsHeaderProperty("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, login");
在我的例子中,当camel抛出异常并返回500错误时,CORS标头不在http响应中。在我的例子中,当camel抛出异常并返回500错误时,CORS标头不在http响应中。您使用哪种版本的camel,您是否尝试过最新版本的camel,你试过最新版本吗