我正在使用Phil Sturgeons RESTFUL
库进行codeigniter。
但我的POST方法有问题。
$这 - >柱( '姓名');
当我尝试捕获值时,上面的代码总是返回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, '<' 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&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"}
任何人都对这些东西有所了解。?
答案 0 :(得分:0)
添加
}其他{
$这 - &GT;响应(_ $ SERVER); }
或
} else {$ this-&gt; response(_ $ POST); }
查看发送给该方法的内容。
答案 1 :(得分:-1)
喜欢这个
$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