I am trying to create a simple API. However, not sure why, but I get true instead of the value that should be returned.
Here is the curl code.
try
{
$target_url = "my url";
$post = array(
'auth_token' => '123456'
);
$ch = curl_init();
if($ch == false)
{
echo "Couldnt initialize curl";
}
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
if (FALSE === $result)
throw new Exception(curl_error($ch), curl_errno($ch));
var_dump($result);
curl_close ($ch);
}
catch(Exception $e)
{
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
The file that receives the content: -
return $_POST['auth_token']
However, the result of var_dump is bool (true) instead of 123456. Why is this happening?
source
share