POST在CodeIgniter中不起作用,而GET可以正常运行

我在CodeIgniter中遇到POST的问题,如果我切换到GET,则无法正常工作。


登录控制器


public function login_check(){

    print_r($this->input->post());

    if($this->input->post('email')!=NULL){

        echo '1';

    }

    else{

        header('Content-Type: application/json');

        echo json_encode( array('a' => $this->input->post('email')));

}

配置文件中CSRF设置为false,而基本URL设置为http:// localhost / xyz /

.htaccess


<IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

路线


$route['api/login-check'] = 'login/login_check';

如果我$this->input->get('email')在邮递员中设置方法GET时进行设置,那绝对可以。


我缺少什么?任何帮助,将不胜感激。


编辑:


邮递员的回复:


Array() {"a":null}


烙印99
浏览 162回答 1
1回答

温温酱

该代码完全按照您的要求执行。代码分解就像...If I get something from $this->input->post('email') then&nbsp;&nbsp; &nbsp; &nbsp;echo '1';else if $this->input->post('email') is NULL&nbsp; &nbsp; &nbsp;then assign NULL to a and return it in a json_encoded array.按照您的代码进行操作可能意味着...public function login_check(){&nbsp; &nbsp; print_r($this->input->post());&nbsp; &nbsp; if($this->input->post('email') == NULL){ // This was !=&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; echo '1';&nbsp; &nbsp; }&nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; header('Content-Type: application/json');&nbsp; &nbsp; &nbsp; &nbsp; echo json_encode( array('a' => $this->input->post('email')));}唯一的变化是在if语句中将!=更改为==。那些“盯着它看得太久,再也看不到它”的简单逻辑错误之一:)更好的建议是使用类似...public function login_check(){&nbsp; &nbsp; print_r($this->input->post());&nbsp; &nbsp; if($this->input->post('email')){&nbsp; &nbsp; &nbsp; &nbsp; header('Content-Type: application/json');&nbsp; &nbsp; &nbsp; &nbsp; echo json_encode( array('a' => $this->input->post('email')));&nbsp; &nbsp; &nbsp; &nbsp; exit();&nbsp; &nbsp; }&nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; &nbsp; // Handle the case where no email was entered.&nbsp; &nbsp; &nbsp; &nbsp; echo '1';&nbsp; &nbsp; }}那应该使您重回正轨。更新:我已经在邮递员中尝试过此方法(只是安装了它),对于POST,您需要像使用GET一样在“正文”而不是“标头”下设置键/值,如果那也是您所缺少的。
打开App,查看更多内容
随时随地看视频慕课网APP