我很抱歉这个问题,但是我只用了2天才处理cakePHP 3.x,我看不出有什么问题。我正在从cakePHP应用程序请求POST请求,但我一直收到POST请求的错误(GET请求很好),我在middleware
方法中使用下面的代码行,我还应该怎么办?这是激活CORS域的正确方法吗?
Application.php
->add(function($request, $response, $next) {
return $next($request, $response)
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Methods', '*')
->withHeader('Access-Control-Allow-Credentials', 'true')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With')
->withHeader('Access-Control-Allow-Headers', 'Content-Type')
->withHeader('Access-Control-Allow-Type', 'application/json');
});
我使用此工具来解决此问题,而不是将任何代码添加到应用程序文件:https://github.com/ozee31/cakephp-cors