0
I created a web API with the code:
<?php
header('Content-type: Application/JSON');
include("../Classes/conexao.php");
if($_SESSION['conectado'] == false){
echo json_encode("Sem resposta do servidor");
}else{
$usuario = $_REQUEST['usuario'];
$senha = $_REQUEST['senha'];
$consulta = "SELECT * FROM estabelecimento WHERE cpf_responsavel = '$usuario' AND senha = '$senha';";
$resultado = $mysqli->query($consulta) or die($mysqli->error);
$n = mysqli_num_rows($resultado);
for ($i=0; $i < $n; $i++) {
$dados[] = $resultado->fetch_assoc();
}
echo json_encode((object)$dados, JSON_PRETTY_PRINT);
}
?>
Which returns the following json:
{
"0": {
"id": "",
"cnpj": "",
"cpf_responsavel": "",
"url_logo": "http",
"senha": "",
"especialidade": "",
"razao_social": "",
"avaliacao": ""
}
}
I created tbm an android app to consume this API using retrofit. The problem is that the app can connect to the service only I can’t get it to save any of the data expressed in json.
You released the CORS in your api?
– Vinicius.Silva
I’m a beginner. I’m not sure.
– José Vinícius
Enabled and did not work
– José Vinícius