4

Below is the code I have written. But its not showing anything on my screen. Am I missing anything?

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

            $reservation_obj['source'] = "website";
            $reservation_obj['location_code'] = "test";
            $reservation_obj['start_date'] = "2010-06-01 19:00";
            $reservation_obj['end_date'] = "2010-06-04 13:50";
            $reservation_obj['action'] = "get_quotes";

            $json = json_encode($reservation_obj);

  $ch = curl_init();

  curl_setopt($ch,CURLOPT_URL,"https://myserver/test.php");
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  curl_setopt($ch,CURLOPT_HEADER, true);
  curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: text/json', 'Content-length: '.strlen($json)));
  curl_setopt($ch,CURLOPT_POST, true);

  curl_setopt($ch,CURLOPT_POSTFIELDS, $json);
  curl_setopt($ch,CURLOPT_VERBOSE, false);

  curl_setopt($ch,CURLOPT_SSLCERT,getcwd()."key/test_services.pem");
  curl_setopt($ch,CURLOPT_SSLCERTTYPE, "PEM");

  curl_setopt($ch,CURLOPT_SSLKEY,getcwd()."key/test_services.p12");
  curl_setopt($ch,CURLOPT_SSLKEYTYPE, "P12");

  curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch,CURLOPT_SSLVERSION, 3);

  $output=curl_exec($ch);

  curl_close($ch);

  print_r($output);

This is what I got on printing

echo "<pre>";
  var_dump(curl_getinfo($ch));
  echo "</pre>";

Below is the output I got. And I server need the ssl certificate thats why I added the ssl things. If am wrong please help me.

array(26) {
  ["url"]=>
  string(68) "https://myserver/test.php"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(0)
  ["header_size"]=>
  int(0)
  ["request_size"]=>
  int(0)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.325151)
  ["namelookup_time"]=>
  float(0.124679)
  ["connect_time"]=>
  float(0.400445)
  ["pretransfer_time"]=>
  float(0)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(-1)
  ["upload_content_length"]=>
  float(-1)
  ["starttransfer_time"]=>
  float(0)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(0) ""
  ["primary_ip"]=>
  string(14) "204.13.111.172"
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(443)
  ["local_ip"]=>
  string(12) "192.168.1.75"
  ["local_port"]=>
  int(36492)
}

After removing it I got this:

rray(26) {
  ["url"]=>
  string(68) "https://wsh.netpark.us/reservation_services/test/ws_reservations.php"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(0)
  ["header_size"]=>
  int(0)
  ["request_size"]=>
  int(269)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(2.50114)
  ["namelookup_time"]=>
  float(0.124669)
  ["connect_time"]=>
  float(0.51286)
  ["pretransfer_time"]=>
  float(1.316726)
  ["size_upload"]=>
  float(124)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(49)
  ["download_content_length"]=>
  float(-1)
  ["upload_content_length"]=>
  float(124)
  ["starttransfer_time"]=>
  float(0)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(0) ""
  ["primary_ip"]=>
  string(14) "204.13.111.172"
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(443)
  ["local_ip"]=>
  string(12) "192.168.1.75"
  ["local_port"]=>
  int(36695)
}
5
  • 1
    print_r(curl_getinfo($ch)); after exec and check what you get http code. if you not verifying SSL why you added SSL code like version etc. Commented Nov 20, 2014 at 7:14
  • Hi, I have printed the stuffs you asked. Please check it.. and let me know your thoughts. Commented Nov 20, 2014 at 7:26
  • you got ["http_code"]=> int(0) means not working it should be 200 for correct Commented Nov 20, 2014 at 7:27
  • try to remove curl_setopt($ch,CURLOPT_SSLCERT,getcwd()."key/test_services.pem"); curl_setopt($ch,CURLOPT_SSLCERTTYPE, "PEM"); let me know result what you get? curl_setopt($ch,CURLOPT_SSLKEY,getcwd()."key/test_services.p12"); curl_setopt($ch,CURLOPT_SSLKEYTYPE, "P12"); curl_setopt($ch,CURLOPT_SSLVERSION, 3); Commented Nov 20, 2014 at 7:28
  • I have updated it please check it. Commented Nov 20, 2014 at 7:33

1 Answer 1

8

Try this after you curl_exec command and before curl_close. That should print any errors.

if($errno = curl_errno($ch)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
}
Sign up to request clarification or add additional context in comments.

4 Comments

Warning: curl_getinfo() expects parameter 1 to be resource, string given in /var/www/html/api/first.php on line 47 NULL
There is no curl_getinfo() in my answer. Also you must run all curl_function before you call curl_close($ch). That's probably your problem.
So curl is not printing errors. You need resolve the SSL issue. The server you are talking to is probably running different ssl version than 3. Try another SSL version. like 2 curl_setopt($ch, CURLOPT_SSLVERSION, 2);
You can find out by using this tool what version are supported SSL Server Test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.