API rest codeigniter POST 方法返回 null


API rest codeigniter POST method return null

我正在使用 Phil Sturgeons RESTFUL 库作为代码点火器。但是我对开机自检方法有问题。

$this->帖子("名称");

当我尝试捕获值时,上面的代码总是返回 null。

这是我的要求: Request Url: http://localhost/api_rest/login Request Method: POST Status Code: 400 Params: { "email": "example@email.com", "password": "balbala" }

function login_post()
{ 
if(!$this->post('email') || !$this->post('password')){
        $this->response(array('error' => 'Email and Password leave blank'),400);
    } 

是的,它的返回状态代码:400 because $this->post('email') or $this->post('password')绝对返回false

也许你应该知道我的错误:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message:  simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '&lt;' not found</p>
<p>Filename: libraries/Format.php</p>
<p>Line Number: 230</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message:  simplexml_load_string(): email=sahal%40seratuscompany.com&amp;password=123456</p>
<p>Filename: libraries/Format.php</p>
<p>Line Number: 230</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message:  simplexml_load_string(): ^</p>
<p>Filename: libraries/Format.php</p>
<p>Line Number: 230</p>
</div>{"error":"Email and Password leave blank"}

有人对这个东西有想法。?

add

} else {

$this->response(_$SERVER); }

} else { $this->response(_$POST); }

以查看发送到该方法的内容。

这样做

     $postdata = file_get_contents("php://input");
      header('Content-type: application/json');
      $obj = json_decode($postdata,true);
      $email=$obj['email'];
      $password=$obj['password'];
      then do the rest