我想加为我的阿卡HTTP API CORS支持:https://github.com/lomigmegard/akka-http-corsCORS与headerValueByName问题(阿卡-HTTP-CORS)阿卡HTTP同时使用<code>akka-http-cors</code>
一切正常时,我基本上将CORS支持一个简单路线,例如:
val route = cors() {
path("ping") {
get {
complete("pong")
}
}
}
与相应的jQuery的电话:
$.ajax({
url: "http://localhost:9000/ping",
type: "GET",
success: function(data) { alert(data); }
});
返回正确“傍”预期
但是,当我尝试提取(服务器端)从请求某些特定标题时,CORS支持的响应似乎是突然被打破。例如,有:
val route = cors() {
headerValueByName("myheader") { (myheader) =>
path("ping") {
get {
complete("pong")
}
}
}
}
与相应的jQuery的电话:
$.ajax({
url: "http://localhost:9000/ping",
type: "GET",
beforeSend: function(xhr){xhr.setRequestHeader('myheader', 'test');},
success: function(data) { alert('Success!' + data); }
});
失败,CORS错误控制台:
XMLHttpRequest cannot load http://localhost:9000/ping.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8080' is therefore not allowed access.
The response had HTTP status code 400.
看来,加入headerValueByName(...)到航路中断cors支持,我不明白为什么。
我也尝试过cors的不同实现(基于自定义特性),并且所有这些行为都是相同的。
我在这里错过了什么?
非常感谢!你完全正确:) – Elsener