[英]how to make https request using php Http_Request2()
我想使用PEAR HTTP_REQUEST2($ URL)883105633527088请求class.我能够提出http请求,但不是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
));
我遇到过这个问题。 修复(对我而言)是使用“curl”作为适配器,例如:
$request = new Http_Request2('https://whatever');
$request->setAdapter('curl');
$response = $request->send();
另请参阅http://pear.php.net/manual/en/package.http.http-request2.config.php上的“SSL 参数”部分
如果您没有明确提供 ssl_cafile 和/或 ssl_capath,对等验证可能会失败,尤其是使用套接字适配器时。
据推测,curl 知道在哪里可以找到可信任的本地 CA 文件。
(带有卷曲的 PHP 5.4.38)。
HTTP_Request2 绝对能够发出 HTTPS 次请求。 可能存在更深层次的错误,例如自定义 SSL 证书会带来问题。
安装Wireshark并检查您实际遇到的错误。 回帖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.