CakePHP + Crud“添加”操作(POST)返回412 Precondition Failed

The Add action (POST method) in CakePHP 3 is not working and it is asking fields that I already informed in json message. Let me explain:

What is my scenario:

  • I'm using WAMP and my Apache is mod_rewrite activated;
  • I'm using composer and I installed CakePHP 3 and CRUD (friendsofcake/crud);
  • I set MySQL database connection correctly;
  • I'm using MySQL example database sakila;
  • I generated Country model from Bake;
  • I changed the AppController class content to load CRUD plugins changing it's content to:
namespace App\Controller;

use Cake\Controller\Controller;

class AppController extends Controller {

    use \Crud\Controller\ControllerTrait;

    public $components = [
        'RequestHandler',
        'Crud.Crud' => [
            'actions' => [
                'Crud.Index',
                'Crud.View',
                'Crud.Add',
                'Crud.Edit',
                'Crud.Delete'
            ],
            'listeners' => [
                'Crud.Api',
                'Crud.ApiPagination'
            ]
        ]
    ];
}
  • I added the Router::extensions(['json', 'xml']) in app/config/routes.php;
  • I added $routes->resources('Country') without deleting the default routes existing in app/config/routes.php;
  • My root site address is http://localhost:8080/mtag

How problem happen:

I'm using Postman for Chrome and setting header Accept and Content-Type value to application/json and sending POST to following link: http://localhost:8080/mtag/country with the following json content:

{
  "country": "BlaBlaBla",
  "last_update": "2015-12-24"
}

But I receive the following status code: 412 Precondition Failed. In returned json:

success: false,
data: {
  code: 412,
  message: "2 validation errors occured",
}

The missing fields indicated is country and last_update but I informed them in json. What I did wrong? Did someone have an example how to use CakePHP CRUD correctly using json?

When I am using Postman for testing the cakePHP CRUD functions I do NOT use application/json for Content-Type but leave it blank. And for the body part just use form-data instead of a json object while using a raw body.