How to retrieve the array from a post sent on Android to a php?

0

Android code:

String caminho = "http://10.0.2.2/system/pages/login";
                HttpURLConnection conn = null;
                BufferedReader reader = null;
                try{
                    URL urlConection = new URL(caminho);
                    conn = (HttpURLConnection) urlConection.openConnection();
                    conn.setDoOutput(true);
                    conn.setRequestMethod("POST");


                    PrintStream ps = new PrintStream(conn.getOutputStream());
                    ps.printf("json", obj.toString());

                    conn.connect();

CakePHP Code:

    public function login(){
    $this->layout = "ajax";

    $dados = json_decode($_REQUEST["json"], true); 
    $ra = $dados["RA"];
    $senha = $dados["Pass"];

    $usuario = array();
    $usuario = $this->User->find("first", ["conditions" => ["User.RA" => $ra, "User.password" => $senha ] ]);


    $retorno = 0;
    if($usuario != null || $usuario != ""){
        $retorno = 1;
    }

    $data = [];

    $data = $usuario["User"];


    echo json_encode(array("dados" => $data));


}

As php returns the array:

{"dados":{"id":"1","status_id":"1","name":"Felipe ","RA":"12342017","email":"[email protected]","password":"123456","data_cancel":null}}
    
asked by anonymous 07.04.2017 / 02:06

0 answers