2
good afternoon!
I have the following function:
function API($conteudoAEnviar) {
try{
$cabecalho = array(
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode(TOTVS_JSON_USER_SECRET . ':' . TOTVS_JSON_PASSWORD_SECRET)
);
$ch = curl_init(TOTVS_URL_REST);
$tpRequisicao = 'POST';
if ($tpRequisicao == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $conteudoAEnviar);
}
if (!empty($cabecalho)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $cabecalho);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resposta = curl_exec($ch);
curl_close($ch);
}catch(Exception $e){
return $e->getMessage();
}
return $resposta;
}
Therefore, I need to create a way for when the $reply presents some error or failure, whether connection or anything, that I can change to a local connection to the database, could give me a light on this, I found nothing in the searches. Is there any function that checks if the connection has been successful?
The function
curl_exec
returns false in case of failure, with this you can usecurl_error
andcurl_errno
to check what happened.– Woss
Marcos, please do not put SOLVED in the title, this is not quite how the site works. If you found the solution, post it as a response in the field below and mark as accepted. Visit our [tour] to learn how it works.
– user28595
Marcos, in a question and answer system, such as [pt.so], there is a clear difference between question and answer: one is question, another is answer. That said, I advise you to publish at all times the solution as answer, not editing the question.
– Woss