5
I have a request on 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 the postman
, I get the expected error, and the json
reply
I would like to use this information in case the user accesses the page or updates the page, instead of creating a new user, it proceed with the registration setting the information that is already saved in the bank, but I’m unable to find the method to retrieve this information when httpstatus != 200
no way!
For example, in js/jquery
, in a request ajax
, when there is server failure, even then there is the possibility to recover the json
reply:
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;
}
});
Have you checked if the "curl_exec($ch)" command returns data about the request? I believe that some of Curl’s methods cause this behavior to occur. Using another HTTP client would solve your problem as well. That’s not an option?
– andreybleme
He is returning
bool(false)
.... It is an option, but if possible wanted to do with Curl– MarceloBoni
The command Curl -I http://www.example.org returns the http status code of the request. Can you verify which method matches your client? Maybe this helps.
– andreybleme
Sorry @andreybleme, I don’t think I understand your question
– MarceloBoni
Also, use Uri with the end bar to avoid WCF responding with the 307.
– Pablo R. Silva