我正在用CakePHP 1.3创建一个JSON 1.3服务。
我希望能够从不同的服务器发送AJAX请求到此want服务。
我知道这在Cake 2+中是小菜一碟,但我无论如何也不能在1.3版本中弄明白它。Based on what I have found in the docs,我已经在我的控制器中尝试了以下操作:
public $components = array('RequestHandler');
function beforeFilter() {
Configure::write('debug', 0);
$this->header('Access-Control-Allow-Origin','*');
$this->header('Access-Control-Allow-Methods','*');
$this->header('Access-Control-Allow-Headers','X-Requested-With');
$this->header('Access-Control-Allow-Headers','Content-Type, x-xsrf-token');
$this->header('Access-Control-Max-Age','172800');
}
不幸的是,这导致了500 ERR_INVALID_RESPONSE
。
我试图用$this->response->header
代替$this->header
,同样的问题。我还尝试了header
而不是$this->header
,并且再次得到了500
的服务器响应。我还尝试将header
块移动到控制器中的操作中,移动到顶级app_controller.php文件中,移动到bootstrap.php文件中,以及移动到视图文件本身中(尝试header
、$this->header
和$this->response->header
的每种变体)。删除Configure::write('debug', 0);
不能解决问题。
见鬼,我甚至在我的.htaccess
文件中有这个:
<IfModule mod_headers.c>
<FilesMatch "\.(json)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
尽管这看起来没什么用。我在Apache的mods- mod_headers.load
文件夹里也有mod_headers.load
。
有谁知道如何在CakePHP 1.3中设置访问控制允许原始头?
发布于 2017-03-29 20:48:03
header("Access-Control-Allow-Origin: *");
我知道这是一个古老的帖子,但我不想为了帮助别人而回答这个问题。
https://stackoverflow.com/questions/33816549
复制相似问题