PHP cURL无法正常工作且未显示任何错误

时间:2014-11-20 07:05:03

标签: php curl

以下是我编写的代码。但它没有在我的屏幕上显示任何内容。我错过了什么吗?

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);

这就是我打印的内容

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

以下是我得到的输出。我服务器需要ssl证书,这就是为什么我添加了ssl的东西。如果错了,请帮助我。

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)
}

删除后我得到了这个:

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)
}

1 个答案:

答案 0 :(得分:3)

在curl_exec命令之后和curl_close之前尝试此操作。这应该打印任何错误。

if($errno = curl_errno($ch)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
}