2016-04-25 114 views
0

我已经写了下面的代码,并无法得到我所提到以下任何调试信息卷曲响应:理解卷曲电话 - curl_exec返回false

能有人帮,找出为什么这个问题curl_exec返回false。

$jwtToken  = getToken(); 
$service_url = "https://example.com/api/Demo/GetProjectAttributes/1484"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $service_url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array (
       "Content-Type: application/x-www-form-urlencoded", 
       "Authorization: Bearer $jwtToken" 
)); 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/mycert.crt"); 

$response = curl_exec($ch); 

if ($response === false) { 
    $info = curl_getinfo($ch); 
    echo '<pre>'; 
    die('error occured during curl exec. Additioanl info: ' . var_export($info)); 
    curl_close($ch); 
} 

我的卷发是越来越失败,我得到以下信息:

array (
    'url' => 'https://example.com/api/Demo/GetProjectAttributes/1484', 
    'content_type' => NULL, 
    'http_code' => 0, 
    'header_size' => 0, 
    'request_size' => 0, 
    'filetime' => -1, 
    'ssl_verify_result' => 0, 
    'redirect_count' => 0, 
    'total_time' => 0.57699999999999996, 
    'namelookup_time' => 0, 
    'connect_time' => 0.28100000000000003, 
    'pretransfer_time' => 0, 
    'size_upload' => 0, 
    'size_download' => 0, 
    'speed_download' => 0, 
    'speed_upload' => 0, 
    'download_content_length' => -1, 
    'upload_content_length' => -1, 
    'starttransfer_time' => 0, 
    'redirect_time' => 0, 
    'redirect_url' => '', 
    'primary_ip' => '104.209.135.21', 
    'certinfo' => 
    array (
), 
    'primary_port' => 443, 
    'local_ip' => '192.168.1.4', 
    'local_port' => 56491, 
) 
+1

,而不是印刷'curl_getinfo'使用'curl_error',它会打印有关的错误的有用信息。 – keune

+0

@keune我用它,它返回空白字符串。 –

回答

0

PHP cURL扩展提供了请求时显示错误,如果失败的功能。

尝试使用他们这样的:

$response = curl_exec($ch); 

if (!$response || curl_errno($ch) !== CURLE_OK) 
{ 
    echo 'cURL error (' . curl_errno($ch) . '): ' . curl_error($ch); 
}