Question

I use this piece of code below to send data to another server via a url and it work successfully. I want to capture the response from the server and process it but I can't seem to capture it.

CODE

$url="http://www.example.com/com_spc/api.php?username=".urlencode($uname)."&password=".urlencode($pwd);

  $ch = curl_init(); // create cURL handle (ch)
if (!$ch) {
   die("Couldn't initialize a cURL handle");
 }
     // set some cURL options
     $ret = curl_setopt($ch, CURLOPT_URL, $url);
     $ret = curl_setopt($ch, CURLOPT_HEADER,         0);
     $ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
     $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
     $ret = curl_setopt($ch, CURLOPT_TIMEOUT,        30);

     // execute
     $ret = curl_exec($ch);

    if (empty($ret)) {
         // some kind of an error happened
    die(curl_error($ch));
        curl_close($ch); // close cURL handler
    } else {
        $info = curl_getinfo($ch);
       curl_close($ch); // close cURL handler

       if (empty($info['http_code'])) {
            die("No HTTP code was returned"); 
       } else {


        }

   }                    
Was it helpful?

Solution

Make sure to set CURLOPT_RETURNTRANSFER to 1. Otherwise curl_exec will not return anything

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