播放框架上的访问控制允许来源 [英] access-control-allow-origin on playframework
问题描述
如何获得允许非原点通话的播放框架?我曾尝试将@Before方法添加到控制器,但从未被ajax客户端调用.
How can I get playframework to allow non-origin calls? I have tried adding a @Before method to a controller, but that never gets called by an ajax client.
@Before
public static void setCORS()
{
Http.Response.current().accessControl("*", "GET,PUT,POST,DELETE", true);
}
我正在尝试为客户端开发人员设置测试API服务器,以进行测试,但这似乎需要禁用Origin限制.
I am trying to setup a test API server for client developers to test against, but that seems to require disabling the Origin restriction.
还有其他人能做到这一点吗?或以其他方式完成此任务?
Has anyone else got this working? or accomplished this in a different way?
更新: 我找到了有关该主题的这篇文章 http://javathought.wordpress. com/2011/12/04/cross-origin-resource-sharing-with-play-framework/
UPDATE: I found this article on the topic http://javathought.wordpress.com/2011/12/04/cross-origin-resource-sharing-with-play-framework/
推荐答案
检查您的浏览器正在尝试执行的操作,它可能首先发送一个OPTION请求以检查允许的内容,这称为预检请求".
Check what your browser is trying to do, it may send an OPTION request first to check what is allowed, this is called "preflight request".
此外,将Access-Control-Allow-Origin设置为*仅在没有凭据的情况下有效.
Also, setting Access-Control-Allow-Origin to * only works without credentials.
这篇关于播放框架上的访问控制允许来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!