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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如何使用PHP Http_Request2()发出https请求脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用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;

这是错误消息:

解决方法

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

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

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

脚本宝典总结

以上是脚本宝典为你收集整理的如何使用PHP Http_Request2()发出https请求全部内容,希望文章能够帮你解决如何使用PHP Http_Request2()发出https请求所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。