java - Trying to connect to local data base with Httppost -
im trying user data date base hosted wamp. sent post request php file return json object app gets stuck in httpresponse response = cliente.execute(request);
this code:
private void obtenerjson() { edittext nombre = (edittext) findviewbyid(r.id.txtnombre); edittext password = (edittext) findviewbyid(r.id.txtpassword); string nombreingresado = nombre.gettext().tostring().trim(); string passwordingresado = password.gettext().tostring().trim(); list<namevaluepair> datos = new arraylist<namevaluepair>(); datos.add(new basicnamevaluepair("nombre", nombreingresado)); datos.add(new basicnamevaluepair("password", passwordingresado)); httpclient cliente = new defaulthttpclient(); httppost request = new httppost("http://10.0.2.2/myfiles/myrequest.php"); bufferedreader lector =null; stringbuffer stringbuffer = new stringbuffer(""); try { request.setentity(new urlencodedformentity(datos)); httpresponse response = cliente.execute(request); httpentity entidad = response.getentity(); if (entidad != null) { string resultado = entityutils.tostring(entidad, "utf-8"); } lector = new bufferedreader(new inputstreamreader(response.getentity().getcontent())); string linea = ""; string separadora = system.getproperty("line.separator"); while ((linea = lector.readline()) != null){ stringbuffer.append(linea + separadora); } lector.close(); interpretarjson(stringbuffer.tostring(), nombreingresado, passwordingresado); } catch (exception e) { } } the code below httpresponse response = cliente.execute(request); doesn't matter. thing when send request, return nothing. use log.d show response content, has nothing show.
this php code:
<?php include('funciones.php'); $nombre = $_post["nombre"]; $password = $_post["pass"]; $result = getsqlresultset("select nombre, password `usuario` nombre=".$nombre.""); while ($row = $result->fetch_array(mysqli_assoc)) { foreach ($row $var => $comparar){ if($nombre == $var ){ $nombreok = true; } if($pass == $var){ $passok = true; } if($nombreok && $passok){ $devolver[] = $row; } } } echo json_encode($devolver); ?> this code funciones.php:
<?php function getsqlresultset($commando){ $mysqli = new mysqli("localhost", "root", "", "basededatos"); /* check connection */ if ($mysqli->connect_errno) { printf("connect failed: %s\n", $mysqli->connect_error); exit(); } $var = $mysqli->execute($commando); //return $mysqli->store_result(); $mysqli->close(); return $var; } ?> i think might using wrong ip, or problem in php code. translate code if necessary. thank you!
Comments
Post a Comment