我刚刚在运行Cake 2.3.8应用程序的Ubuntu 12.04 apache2服务器上添加了SSL。我确保添加https://...在每一个电话前,并使用grep进行确认。据我所知,没有被阻止的脚本。当我试图用AJAX从JS文件向我的服务器发出AJAX发布请求时,我会收到一个类似的错误
The request has been black-holed
Error: The requested address '/sorts/available_spaces' was not found on this server.
在我发出POST请求的JS文件中,我有
$.post("https://www.mywebsite.com/sorts/available_spaces",{'customerID' : self.customerID, 'arrivalDate' : self.arrivalDate},function(data) {
data = JSON.parse(data);
for(i=0;i<data.length;i++){
self.roomNumberList.push({spaceNumber: data[i].spaceNumber, roomID: data[i].roomID});
}
});
在我的SortsController中,我甚至试图将访问控制原点设置为允许一切并禁用安全性(暂时),但我仍然收到黑洞请求
//SortsController
var $components = array('Security');
public function beforeFilter(){
$this->response->header('Access-Control-Allow-Origin', '*');
$this->Security->unlockedActions = array('available_spaces', check_reservation');
$this->Auth->allow('available_spaces','check_reservation');
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
parent::beforeFilter();
}
即使在available_spaces方法中,也不会调用SortsController之外的其他方法或任何东西。我的排序模型中没有任何东西,而且我的AppController中根本没有调用安全性。
这是堆栈跟踪。除了路由之外,我甚至没有看到任何关于SortsController或方法的提及。
CORE/Cake/Controller/Component/SecurityComponent.php line 241 → SecurityComponent->blackHole(SortsController, string)
[internal function] → SecurityComponent->startup(SortsController)
CORE/Cake/Utility/ObjectCollection.php line 132 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 248 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 675 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 184 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(SortsController, CakeRequest, CakeResponse)
APP/webroot/index.php line 118 → Dispatcher->dispatch(CakeRequest, CakeResponse)
在启用安全组件的情况下,通过Ajax发布的帖子将无法工作。
根据http://whatswhat.no/development/framework/cakephp-2/465-making-a-jquery-ajax-call-with-security-component-activated-in-cakephp-2您需要将您的操作添加到安全组件的解锁操作中:
public function beforeFilter() {
parent::beforeFilter();
$this->Security->unlockedActions = array('ajax_action');
}