php – 卷曲错误:错误:1408F10B:SSL例程:SSL3_GET_RECORD:版本号错误

我有以下代码,它给我“卷曲错误:错误:1408F10B:SSL例程:SSL3_GET_RECORD:错误的版本号”错误.

$url='https://mysite/login';

$clientcert  =       "C:\\client.crt"; 
$keyfile     =       "C:\\server.key"; 
$challenge   =       "passphrase"; 
$CAFile      =       "C:\\server.pem";
print "<bR><BR>$challenge<br><br>"; 
print "<bR><BR>$keyfile<br><br>"; 
print "<bR><BR>$clientcert<br><br>"; 
print "<bR><BR>$CAFile<br><br>"; 

$header=array('contentType:application/json','MY-API-Key:34sdSDFSDFxcvxcvxcvEEE11','Content-Type:application/json','Accept: application/json');

$username=base64_encode("uname");
$password=base64_encode("pswd");

$ch = curl_init(); 
if(FALSE==$ch)
  echo "Unable to create Url Object" . "\n";

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
//curl_setopt($ch, CURLOPT_POSTFIELDS,"$username:$password");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0");       
curl_setopt($ch, CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 
curl_setopt($ch, CURLOPT_SSLCERT, $clientcert); 
curl_setopt($ch, CURLOPT_CAPATH, $CAFile); 
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $challenge); 
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $challenge); 
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM'); 
curl_setopt($ch, CURLOPT_SSLKEY, $keyfile); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
//curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
  $response = curl_exec($ch);  
 $info=curl_getinfo($ch);

我使用与服务器相同的一个密码和sha384算法生成证书.所以我有私钥,证书(.crt文件)和密码,我已经在apache和curl脚本中设置了.
请提出可能存在的问题.

最佳答案 我得到了相同的错误我通过改变解决了它

sslVersion = 3 

更新到

sslVersion = 'all'

这个对我有用

在你的情况下,我认为你需要改变

curl_setopt($ch, CURLOPT_SSLVERSION,3);

curl_setopt($ch, CURLOPT_SSLVERSION,'all'); 

它应该工作

点赞