WANDERSONPS Posted December 22, 2022 Share Posted December 22, 2022 Amigos, tudo bem? Como faço para recuperar o código do header http de response de uma API? Quero saber se o retorno é code: 204 (que é o code de sucesso do DELETE no insmonia). Mas no meu exemplo só apresenta o code 200. O exemplo que estou usando é: <?php $access_token = "xxx"; if(isset($_GET['key'])){ $link = "https://pix.tecnospeed.com.br/api/v1/companies/".$_GET['key']; }else{ header("Location: Company_02_ListAll.php"); exit(); } $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => $link, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "DELETE", CURLOPT_POSTFIELDS => "", CURLOPT_HTTPHEADER => [ "Authorization: Bearer $access_token", "Content-Type: application/json" ], // defindo os parametros do Agent_HTTP do usuário CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"] ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { // Converter retorno para ARRAY $retorno = json_decode( $response, true ); // CODE HEADER HTTP $x = http_response_code(); echo "<p>Code: ".$x ; } Agradeço ajuda deste já. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now