Question

I have written a PHP script that uses curl_seopt to send data to a server (www.googleapis.com/admin/directory/v1/users).

Now I want to know what response did I get? Hopefully "200 OK". How can I print that response or some helpful information to the screen?

Was it helpful?

Solution

$ch=curl_init("www.googleapis.com/admin/directory/v1/users");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result=curl_exec($ch);
curl_close($ch);

with curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); it will return the result on success, FALSE on failure.

with curl_setopt($ch,CURLOPT_RETURNTRANSFER,false); it will return TRUE on success or FALSE on failure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top