Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RESTAPI调用的Cakephp验证组件行为_Php_Rest_Cakephp_Postman - Fatal编程技术网

RESTAPI调用的Cakephp验证组件行为

RESTAPI调用的Cakephp验证组件行为,php,rest,cakephp,postman,Php,Rest,Cakephp,Postman,我正在尝试实现一个api_登录函数。 我的UsersController中有两个用于登录的函数 1) 登录 和2)api_登录 public function api_login() { if($this->request->is('post')) { if($this->Auth->login()) { $message = 'success'; $this->

我正在尝试实现一个api_登录函数。 我的UsersController中有两个用于登录的函数 1) 登录

和2)api_登录

public function api_login() {
        if($this->request->is('post')) {
            if($this->Auth->login()) {
                $message = 'success';
                $this->set(array('message' => $message, '_serialize' => 'message'));
            }
            else {
                $message = 'fail';
                $this->set(array('message' => $message, '_serialize' => 'message'));
            }
        }
    }
登录
功能工作正常。但是我对api\u登录有问题 当我使用像POSTMAN这样的REST客户机时,我会将请求发布到
http://myProject/api/users/login.json
,我无法登录(每次显示“失败”)我尝试使用正确的凭据发布和登录

我发布的文件是用户名和密码。我不明白我做错了什么。任何帮助都将不胜感激。
如果我没有完整描述问题,请询问。

您需要在登录中传递您的帖子数据,以检查用户名和密码

if ($this->Auth->login($this->request->data))

希望这对您有所帮助

您是否获得了两个函数的“$this->request->data”的正确值。尝试在身份验证登录之前打印请求数据,并比较结果是否相同。无论您的登录函数得到什么值,都应该为api_kogin函数打印相同的值。
if ($this->Auth->login($this->request->data))