如何使用CodeIgniter在RESTful API中发送post值


How to send post values in RESTful API using CodeIgniter?

我不知道如何获取值,请帮我解决这个问题。告诉我一个参考,如果有人已经有代码,请分享。我还很好奇如何用带有完整过程的RESTful API加载带有cURL的spark

<?php class LoginController extends CI_Controller {
    public function index()
    {
        $this->load->view('admin/header');
        $this->load->view('admin/index');
        $this->load->view('admin/footer');
    }
    public function loginCon(){
$this->load->Library('rest');
        $this->form_validation->set_rules('email', 'E-mail', 'required|trim');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_error_delimiters("<p class='text-danger'>", "</p>");
        if ($this->form_validation->run()==false)
        {
            $email = $this->input->post('email');
            $password = $this->input->post('password');
            $this->session->set_flashdata('login_failed', 'Invalid User Name Password');
        }else{
            $config = array('server' => "http://api.amid.tech/hsApiV2/api/demo.php/",
                'http_user' => 'admin',
                'http_pass' => 'xxxxx',
                'http_auth' => 'basic',
            );
            $this->rest->initialize($config);
            $method = 'post';
            $param = array(
                'UserEmail' => $this->input->post('email'), // works fine here
                'UserPass' => $this->input->post('password'),
                'UserRoleId'=>1
            );
            $uri = 'adminlogin';
            $this->rest->format('application/json');
            $result = $this->rest->{$method}($uri, $param);
            echo $result;
          $this->load->view('admin/admin_header');
            $this->load->view('admin/sidebar');
            $this->load->view("admin/dashboard");
            $this->load->view('admin/dashboard.php');
        }

    }
    public function registerd()
    {
        $this->load->view('admin/header');
        $this->load->view('admin/registration');
        $this->load->view('admin/footer');
    }
} ?>

要获得原始输入,请尝试

// get the raw POST data
$rawData = file_get_contents("php://input");

验证尝试

$this->form_validation->set_rules($rawData['email'], 'E-mail', 'required|trim');