Android Question Unstable server responses

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings as I could improve the server's unstable responses, the problem is that it does not give me security and in some cases gives the answer and in others only an error ... the information is present for the different queries. I have updated the database.

B4X:
Response from server: [{"ID":"1175","NOMBRE":"CLAVO CORRIENTE CON CABEZA 2-1\/2 PULG (GRANEL)","CODIGO":"1137","REFERENCIA":"1174","PRECIO":"797,9","FECHA":"21-2-18","EMPAQUE":"KILOGRAMO","FOTO":"https:\/\/www.M.com\/Content\/Thumbnails\/01137.png","FOTO1":""}


B4X:
ResponseError. Reason: Internal Server Error, Response: <h1 style='color:#497A97;font-size:12pt;font-weight:bold'>500 - Internal Server Error


B4X:
    Servidor: mysql via TCP/IP
    Tipo de servidor: MySQL
    Versión del servidor: 5.1.55 - Source distribution
    Versión del protocolo: 10
    Usuario: xxxxxxx@localhost
    Conjunto de caracteres del servidor: UTF-8 Unicode (utf8)

Servidor web

    Apache/1.3.37 (Unix) mod_ssl/2.8.28 OpenSSL/0.9.6b mod_fastcgi/2.4.2
    Versión del cliente de base de datos: libmysql - 5.1.55
    extensión PHP: mysql Documentación

phpMyAdmin

    Acerca de esta versión: 4.0.10.16

B4X:
job.PostString("http://accccccc.com/"&BASE, Query)

B4X:
<?php

$databasehost = "localhost";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";

$con = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename) or die(mysqli_error($con));
mysqli_set_charset ($con , "utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, $query);

if (mysqli_errno($con)) {
   header("HTTP/1.1 500 Internal Server Error");
   echo $query.'\n';
   echo mysqli_error($con);
}
else
{
   $rows = array();
   while($r = mysqli_fetch_assoc($sth)) {
     $rows[] = $r;
   }
   $res = json_encode($rows);
    echo $res;
    mysqli_free_result($sth);
}
mysqli_close($con);
?>
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
thanks Erel ... because this is unstable ... this can be corrected, so I do not have to vary my application.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
It might also be worth mentioning that you are making a very large security hole with your design here. Not only are you not using https, but you're also executing database queries as received from the device. It's trivial for somebody with bad intentions to do very bad things with your database, if you have a little bad luck.

I would only use this kind of solution for (well) known users, in a closed environment, such as a LAN.

Just a friendly note.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i do not see the output of "echo mysqli_error($con);" above.
are u sure this 500 error comes from your php where you add it at header?
maybe enable detail error messages at your web server for testing.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…