$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'hello_world');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CAINFO, getcwd().'/ca.pem');
curl_setopt($curl, CURLOPT_SSLCERT, getcwd().'/client.pem');
curl_setopt($curl, CURLOPT_SSLKEY, getcwd().'/key.pem');
$post = array(
// ...
);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, join('&', $post));
$curl_result = curl_exec($curl);
$error = curl_error($curl);
var_dump($curl_result);
var_dump($error);
curl_close($curl);
此脚本在控制台“php simple.php”中工作 但是这个脚本在浏览器中不起作用
布尔值假
字符串'NSS:找不到证书的私钥:PEM令牌#1:client.pem'(长度= 67)
请帮助
` cd /path/to/simple.php; ls -la -rwxrwxrwx 1 ujin apache 1.4K Jan 19 19:03 simple.php -rw-r--r-- 1 ujin apache 2.6K Jan 19 15:58 ca.pem -rw-r--r-- 1 ujin apache 1.6K Jan 19 15:59 client.pem -rw-r--r-- 1 ujin apache 1.1K Jan 19 16:18 key.pem `
答案 0 :(得分:1)
您的脚本无法找到ca.pem和朋友。有些事要尝试
http://at2.php.net/manual/en/function.curl-setopt.php告诉我们,CURLOPT_CAINFO需要一条绝对路径!
编辑(与@UJin讨论后):请尝试绝对路径:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'hello_world');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$cwd=getcwd();
//DEBUG
echo "cwd=$cwd\n";
curl_setopt($curl, CURLOPT_CAINFO, "$cwd/ca.pem");
curl_setopt($curl, CURLOPT_SSLCERT, "$cwd/client.pem");
curl_setopt($curl, CURLOPT_SSLKEY, "$cwd/key.pem");