I have a request in my API:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'link da api');
curl_setopt( $ch, CURLOPT_FAILONERROR, true );
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $params);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
$db_save_user = json_decode(curl_exec($ch)); //recupera o json quando o httpstatus = 200
$http_status = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
Using postman
, I get the expected error, and the json
response
I would like to use this information in case the user accesses the page or refreshes the page, instead of creating a new user, he continues with the registration setting the information that is already saved in the bank, but I can not find the method to retrieve this information when there is httpstatus != 200
at all!
Forexample,injs/jquery
,inaajax
request,whenthereisaserverfailure,thereisstillthepossibilityofretrievingjson
response:
jQuery.ajax({url:"link da api",
type: "POST",
data: data,
success: function(returnjson){
console.log(returnjson.id_customer);
return true;
},
error: function(returnjson) {
if(returnjson.status == 409){
console.log(returnjson.responseJSON.id_customer);
return true;
}else{
alert("Ocorreu algum erro, tente novamente ou entre em contato com o suporte técnico.");
}
return false;
}
});