0

Good afternoon. I am facing a very specific problem. It turns out that I have an application running on a server in the clouds (hostigator - php) that makes calls via curl on a server hosted on my client. (apache - php). Access is made via IP or ddns. When I make the call (get) right in the browser, it returns json normally, but when I call the server in the clouds (hostigator) it returns an empty string.

No php that is on the server has the following header.

header ("Content-Type: application / json");

Calling method

$app->get('/getCidades/:id',    function ($id) use ($app, $db) {
$data = json_decode($app->request()->getBody());   
$ch = curl_init();
$url = $_SESSION['ip'] . $GLOBALS['servico'] . "getCidades/" . $id;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,10); //timeout in seconds
curl_setopt($ch,CURLOPT_TIMEOUT, 20); // same for here. Timeout in seconds.
$response = curl_exec($ch);
curl_close ($ch); //close curl handle    
echo $response;
}
);

Server in client header("Content-Type: application/json"); header("Content-type: text/html; charset=utf-8");

$app->get(
'/getCidades/:id', 
function ($id) use ($app) {        
$conexao = ibase_connect( $GLOBALS['hostname'], $GLOBALS['usuario'],                 
$GLOBALS['senha'] ) or die( 'Erro ao conectar: ' . ibase_errmsg() );
$Ds_Query = "select DISTINCT PESSOAS.cidade2, PESSOAS.uf2 from PESSOAS where 
cidade2 <> '' and uf2 is not null order by cidade2";
$Ds_Retorno = ibase_query( $Ds_Query );
$results = array();
while ( $Ds_Linha_Banco = ibase_fetch_row( $Ds_Retorno ) )
{
$row = new Cidade();
$row->cidade = clean($Ds_Linha_Banco[0]);
$row->uf = $Ds_Linha_Banco[1]; 
$results[] = $row;
}
ibase_close($conexao);
echo json_encode(array("list"=>$results));    
}  
);
1
  • something wrong in headers Commented Aug 2, 2018 at 15:49

1 Answer 1

1

Maybe you are missing the parameter CURLOPT_POST. When you open a url using a web browser, the request is processed using a GET method, but in this case the HTTP VERB is not defined. Try add this and post back to us :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.