如何使用php Http_Request2()发出https请求 [英] how to make https request using php Http_Request2()

查看:447
本文介绍了如何使用php Http_Request2()发出https请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用pear http_request2($ url)类发出一个https请求. 我能够发出http请求,但不能发出https.该网站同时支持http和https.服务器没有响应https的问题.

i want to make a https request using pear http_request2($url) class. i am able to make http request but not https. and the website facilitate both http and https. No prob with server responding to 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)

推荐答案

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

The comment to disable certificate verification was the key for me.

$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请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆