php get error连接中的未知SSL协议错误

时间:2018-02-19 10:11:23

标签: php php-openssl

我应该连接到使用Basic Authntication和GET方法获取json字符串的Web服务。当我在浏览器中输入url时,我得到了正确的结果但是当我使用cUrl尝试它时,我得到错误:

Unknown SSL protocol error in connection to www.example.com:443 

这是代码:

$url = "https://www.example.com/api/Voucher/VerifyDiscountCode?discountCode=test&cellPhoneNumber=123456&otp=false";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
//curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, "test:test");
$data = curl_exec($curl);
if($data === false) $data = curl_error($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

echo $data;

注意:这个代码在我的本地电脑上工作但在服务器上不行,这很有趣!我相信这不是防火墙的事情。不确定它是来自php配置还是什么?

0 个答案:

没有答案