2016-09-26 158 views
0

我有四個文件從客戶端提供。無法加載PEM客戶端證書,OpenSSL

  • test.jks
  • test.pem
  • key.pub
  • test.p12

我必須在使用curl這個網址發送JSON數組。所以我很困惑什麼是使用其他文件?像.p12,.jks。上述文件的關鍵是什麼? 我開始使用.pem文件包含使用此鏈接: How to send a curl request with pem certificate via PHP?

所以,我得到以下錯誤。

錯誤:

Curl Error: could not load PEM client certificate, OpenSSL error error:0906D06C:PEM routines:PEM_read_bio:no start line, (no key found, wrong pass phrase, or wrong file format?)No HTTP code was returned

代碼:

$url = "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 

$pemFile = tmpfile(); 
fwrite($pemFile, "test.pem");//the path for the pem file 
$tempPemPath = stream_get_meta_data($pemFile); 
$tempPemPath = $tempPemPath['uri']; 
curl_setopt($ch, CURLOPT_SSLCERT, $tempPemPath); 

//curl_setopt($ch, CURLOPT_SSLCERT, "test.pem"); 
curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM"); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); 
curl_setopt($ch, CURLOPT_POST, True); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 

$result = curl_exec($ch); 

if(!$result) 
{ 
    echo "Curl Error: " . curl_error($ch); 
} 
else 
{ 
    echo "Success: ". $result; 
} 

    $info = curl_getinfo($ch); 

    curl_close($ch); // close cURL handler 

    if (empty($info['http_code'])) { 
      die("No HTTP code was returned"); 
    } else { 
     // load the HTTP codes 
     $http_codes = parse_ini_file("path/to/the/ini/file/I/pasted/above"); 

     // echo results 
     echo "The server responded: <br />"; 
     echo $info['http_code'] . " " . $http_codes[$info['http_code']]; 
    } 
+0

選中此[查詢](http://stackoverflow.com/questions/20837161/openssl-pem-routinespem-read-biono-start-linepem-lib-c703expecting-truste)。也許它可以幫助你。 – James

+0

@詹姆斯我試着用這個代碼也是兄弟,但同樣的錯誤。 – Bhavin

+0

@james我有一個問題,我必須在代碼中包括密碼或不?因爲當我嘗試使用curl命令行時,此證書與密碼一起工作正常 – Bhavin

回答

0

的問題就解決了。這是一代pem文件中的一個錯誤。