安卓应用程序与rest api php代码点火管理面板


Android App with rest api php codeigniter admin panel

想要将安卓应用程序与rest api php codeigner管理面板连接我在连接管理面板codeigner时遇到问题。。。rest api连接登录提交按钮

/* PHP */
<?php include ('header.php');?>
<div class="container"?>
    <?php echo form_open('logincontroller/admin_login', ['class'=>'form-horizontal']) ?>
    <fieldset>
        <legend>LOGIN</legend>
        <div class="row"><!-- user email field -->
            <div class="col-lg-6">
                <div class="form-group">
                    <label for="inputEmail" class="col-lg-2 control-label">Email</label>
                    <div class="col-lg-10">
                        <?php echo form_input(['name'=>'email' , 'class'=>'form-control','placeholder'=>'Email','value'=>set_value('email')]);?>
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <?php echo form_error('email');?>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-6">
                <div class="form-group">
                    <label for="inputPassword" class="col-lg-2 control-label">Password</label>
                    <div class="col-lg-10">
                        <?php echo form_password(['name'=>'password' , 'class'=>'form-control','placeholder'=>'Password','value'=>set_value('password') ]);?>
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <?php echo form_error('password');?>
            </div>
        </div>
        <div class="form-group">
            <div class="col-lg-10 col-lg-offset-2">
                <?php echo form_reset(['name'=>'reset','value'=>'Reset','class'=>'btn btn-default']);
                echo form_submit(['name'=>'submit','value'=>'Login' ,'class'=>'btn btn-primary']);?>
            </div>
        </div>
    </fieldset>
</form>
</div>
<?php include ('footer.php');?>

我想你会想对表单操作字段做点什么,或者用javascript捕获提交事件,并向你的android应用程序发出ajax请求。

         HttpClient client = new DefaultHttpClient();
            String responseString = null;
            try {
                HttpResponse response = client.execute(new HttpGet("http://api.amid.tech/product/0"));
                StatusLine statusLine = response.getStatusLine();
                if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    response.getEntity().writeTo(out);
                    out.close();
                    responseString = out.toString();
                    //Whatever you wanna do with the response
                } else {
                    //Close the connection.
                    response.getEntity().getContent().close();
                    Log.e("Anas", statusLine.getReasonPhrase());
                    throw new IOException(statusLine.getReasonPhrase());
    <?php
class LoginController extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library("session");
    }
    public function index()
    {
        if($this->session->userdata("id"))
        {
            return redirect('admincontroller/dashboard');
        }
        else
        {
            $this->load->view('index');
        }
    }
    public function admin_login()
    {
        $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())
        {
            $email = $this->input->post('email');
            $password = $this->input->post('password');
            $link = 'http://api.amid.tech/admin/' . $email . '/' . $password;
            $data = (array)json_decode(@file_get_contents($link, true));
                        if (isset($data) && count($data) == 0)
                        {
                            $this->session->set_flashdata('login_failed','Invalid User Name Password');
                            $this->load->view('index');
                        }
                        else if ($email == $data['email'] && $password == $data['password'])
                        {
                            $Record = array(
                                "id" => $data["id"],
                                "name" => $data["name"],
                                "email" => $data["email"],
                                "password" => $data["password"]
                            );
                            $this->session->set_userdata($Record);
                            return redirect('admincontroller/dashboard');
                            //$this->load->view('admin/dashboard');
                        }
        }
        else
        {
            // echo"false";
            $this->load->view('index');
            //echo validation_errors('');
        }
    }
    public function logout()
    {
        $this->session->sess_destroy();
        redirect('logincontroller/index');

    }

}
?>

正确答案