加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何使用PHP Http_Request2()发出https请求

发布时间:2020-12-13 22:03:34 所属栏目:PHP教程 来源:网络整理
导读:我想使用pear http_request2($url)类发出https请求. 我能够发出http请求但不能https.并且该网站便于http和https.服务器响应https没有问题. require 'HTTP/Request2.php'; $url = 'https://collegedb2.ferryfair.com'; $r = new Http_Request2($url); $r-setM
我想使用pear http_request2($url)类发出https请求.
我能够发出http请求但不能https.并且该网站便于http和https.服务器响应https没有问题.

require 'HTTP/Request2.php';
    $url = 'https://collegedb2.ferryfair.com';
    $r = new Http_Request2($url);
    $r->setMethod(HTTP_Request2::METHOD_POST);
    try {
        $response = $r->send();
    } catch (Exception $exc) {
        $es = $exc->getTraceAsString();
        $ets=$exc->__toString();
        $egc=$exc->getCode();
        $egl=$exc->getLine();
        $egm=$exc->getMessage();
        $egt=$exc->getTrace();
        $response = null;
    }
    $page = $response->getBody();
    echo $page;

这是错误消息:

$egm=(string) Unable to connect to ssl://collegedb2.ferryfair.com:443. Error: stream_socket_client(): unable to connect to ssl://collegedb2.ferryfair.com:443 (Unknown error)

解决方法

禁用证书验证的评论对我来说很关键.

$request = new HTTP_Request2('https://someserver.com/somepath/something',HTTP_Request2::METHOD_POST);

$request->setConfig(array(
    'ssl_verify_peer'   => FALSE,'ssl_verify_host'   => FALSE
));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读