如何通过https允许PHP REST请求过期证书

时间:2016-04-28 07:25:09

标签: php ssl

如果证书过期,是否有办法允许PHP连接到https网址?像浏览器中的安全例外。

如果证书有效,则以下代码将无效,但如果证书有效,则以下代码无效。

<?php

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://myURL/...,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "authorization: Basic abcdefghijkl",
        "cache-control: no-cache",
    ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

1 个答案:

答案 0 :(得分:0)

<?php

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://myURL/...,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "authorization: Basic abcdefghijkl",
        "cache-control: no-cache",
    ),
    CURLOPT_SSL_VERIFYPEER => false
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);