0

If I go directly to the URL with the right params in the URL, I get a success response.

The URL looks like

https://api.theService.com/send?client_id=54&token=7545h5h554&format=json

In PHP, I tried something like

error_reporting(E_ALL);
ini_set('display_errors', 1);

$client_id = 54;
$token = '7545h5h554';

$ch = curl_init('https://api.theService.com/send?client_id='.$client_id.'&token='.$token.'&format=json');

// Send the request
$response = curl_exec($ch);

// Check for errors
if($response === FALSE){
    die(curl_error($ch));
}

// Decode the response
$responseData = json_decode($response, TRUE);

echo "<pre>";
echo print_r($responseData);
echo "</pre>";

However I never get a response with the above code.

Dan P.
  • 1,707
  • 4
  • 29
  • 57
  • possible duplicate of [PHP CURL & HTTPS](http://stackoverflow.com/questions/4372710/php-curl-https) – Paul Dessert Apr 28 '14 at 23:44
  • I don't get any error. – Dan P. Apr 28 '14 at 23:47
  • For the person who put "This question may already have an answer here:" -- you may want to take it off. The answer was related to something else (see tuga and comments to his answer) – Dan P. Apr 28 '14 at 23:58

1 Answers1

0

Try this:

$client_id = 54;
$token = '7545h5h554';
$url  = "https://api.theService.com/send?client_id=$client_id&token=$token&format=json";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //waits 10 seconds for response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch) or die(curl_error($ch));
echo $page;

You should also try checking the error messages in curl_error().
http://www.php.net/curl_error

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268