我目前正在使用证书的网站上测试 API,方法是在本地 Windows 计算机上的命令行中执行使用curl 的 php 脚本。但该脚本从未成功到达服务器。我已经查找了这个明显频繁的错误的解决方案,并尝试了以下方法,但没有成功:
这是我用于测试的脚本(我仅在命令行中使用 php 执行它):
$data = 'username=myuser&password=mypassword';
$ch = curl_init('https://my.website.com/auth');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
如果我取消注释其中的两行以完全绕过证书验证,则它可以正常工作,但我想避免这种情况。
在所有情况下,我都尝试了包含斜杠和反斜杠的路径,我确信使用了正确的 php.ini,并且 php 确实可以访问 .pem 文件位置。php 脚本的输出证实了这一点(我已经替换了我正在使用的实际 url):
> * …Run Code Online (Sandbox Code Playgroud)