I'm experiencing a strange issue with CURLINFO_HTTP_CODE
in PHP where it is returning a 0 even though the cURL request itself has been successful. Essentially I'm using a for loop to perform changes to base bids for every campaign ID. I'm then trying to catch cases where the HTTP status code of the request is not equal to 200 and display these to the browser.
The issue is that return var_dump($this->info)
returns int(0)
which doesn't make sense if the request has been succesful. I've checked this by making a GET request to the campaign ID. The code I'm using is below:
class curl
{
public $info;
public $json_output;
public function curlPut($url, $JSON, $token)
{
$ch = curl_init($url);
$popt = array(
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_POSTFIELDS => $JSON,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization:'.$token.''
));
curl_setopt_array($ch, $popt);
$this->info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->json_output = curl_exec($ch);
curl_close($ch);
return var_dump($this->info);
}
};
Does anyone know why my script is showing this behaviour?
Any comments would be appreciated!
Thanks,
Sam