2016-09-26 7 views
0

クライアント側から4つのファイルが提供されています。PEMクライアント証明書をロードできませんでした。OpenSSL

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

私はカールを使用して、このURLに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

@James私はこのコードも弟が同じエラーを試みた。 – Bhavin

+0

@james私はパスフレーズをコードに含める必要があるかどうかという質問が1つありますか?なぜなら、curlコマンドラインを使って試してみると、この証明書はパスフレーズでうまく動作しているからです。 – Bhavin

答えて

0

。それはpemファイルの生成の誤りでした。

関連する問題