2013-08-01 128 views
4

我想解析各種ssl/https站點。Zend Framework 2 Zend_Http_Client SSL連接錯誤

例如,我想要https://microsoft.de的內容,但它不起作用。以下誤差修改顯示:

Fatal error: Uncaught exception 'ErrorException' with message 'stream_socket_enable_crypto() [<a href='function.stream-socket-enable-crypto'>function.stream-socket-enable-crypto</a>]: 
SSL operation failed with code 1. 
OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' 
in C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php:276 
Stack trace: #0 [internal function]: Zend\Stdlib\ErrorHandler::addError(2, 'stream_socket_e...', 'C:\Users\Privat...', 276, Array) #1 C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php(276): stream_socket_enable_crypto(Resource id #35, true, 2) 
#2 C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client.php(1356): Zend\Http\Client\Adapter\Socket->connect('microsoft.de', 443, true) #3 C:\Users\Privat\Desktop\Server\Apache2\htdocs\ in C:\Users\Privat\Desktop\Server\Apache2\htdocs\allsubmitter\server\vendor\zendframework\zend-http\Zend\Http\Client\Adapter\Socket.php on line 299 




$config = array(
     'adapter'  => 'Zend_Http_Client_Adapter_Socket', 
     'ssltransport' => 'tls' 
); 
$client = new \Zend\Http\Client("https://microsoft.de"); 

回答

3

你可以告訴客戶端不驗證SSL,請嘗試以下配置:

$clientConfig = array(
    'adapter' => 'Zend\Http\Client\Adapter\Curl', 
    'curloptions' => array(
     CURLOPT_FOLLOWLOCATION => TRUE, 
     CURLOPT_SSL_VERIFYPEER => FALSE 
    ), 
); 

$this->_client = new \Zend\Http\Client('https://microsoft.de', $clientConfig); 
+0

我aslso認爲你是混合ZF2和ZF2符號存在,使用下劃線而不是namspaced類名。 – Andrew

+0

爲什麼你的意思是我混合zf2和zf2。爲什麼zf2和zf2:D。爲什麼你說我應該使用「舊」風格的下劃線而不是命名空間?或者我不瞭解你。非常感謝你。 和爲什麼你的代碼工作像魅力,但不是與「默認」fsocket? – user2521436

+0

您正在使用適配器的舊式​​下劃線,它需要像ZF2中的我的名稱空間。但使用curl適配器可以禁用SSL檢查,如果你檢查文檔,你也可以通過Socket來完成,很高興幫助你:) – Andrew