Rest服务器在httpget请求后返回警告


Rest server returns warning after an httpget Request

在我的rest服务器上,我有一个函数,它向服务器的数据库添加一个新行,并返回一个响应:

这是我的功能

    private function addUser(){
        echo "addUser'n ";
        $login=$_REQUEST['login'];
        $password=$_REQUEST['password'];
        $firstname=$_REQUEST['firstname'];
        $lastname=$_REQUEST['lastname'];
        $sex=$_REQUEST['sex'];
        $situation=$_REQUEST['situation'];
        $email=$_REQUEST['email'];
        $telephone=$_REQUEST['telephone'];
        $address=$_REQUEST['address'];
        echo $login.$password.$address;
        $sql = "insert into users(login,password,firstname,lastname,sex,situation,email,telephone,address)
        values('$login','$password','$firstname','$lastname','$sex','$situation','$email','$telephone','$address')" ;
        if (!mysql_query($sql))
          {
            die('Error: ' . mysql_error());
          }
          else
          {
            echo 'SUCCESS: ';
          }
        $success = array('status' => "Success", "msg" => "Successfully one record created.");
        $this->response($this->json($success),200);
    }

但在响应中,我不断收到这些警告

addUser samuel0757bed3d74ccc8fc8e67a13983fc95dca20940777avbombardierSUCCESS:
Warning: Cannot modify header information - headers already sent by (output started at /mnt/153/sda/7/8/darate/rest/api.php:140) in /mnt/153/sda/7/8/darate/rest/Rest.inc.php on line 115
Warning: Cannot modify header information - headers already sent by (output started at /mnt/153/sda/7/8/darate/rest/api.php:140) in /mnt/153/sda/7/8/darate/rest/Rest.inc.php on line 116
{"status":"Success","msg":"Successfully one record created."}

以下几行似乎是错误的来源

private function set_headers(){
            header("HTTP/1.1 ".$this->_code." ".$this->get_status_message());//line 115
        header("Content-Type:".$this->_content_type);//116
    }

您正在回显内容:

echo $login.$password.$address;

在设置标题之前。

顺便说一下,您不应该使用get来添加内容,而应该使用POST