[英]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.