2013-10-19 61 views
0

我有兩個web應用程序,只是說webAppA和webAppB。 webAppA部署在通過https 8443運行的tomcat7中。它使用基本身份驗證方案提供RESTful服務。 webAppB是基於php的web應用程序,它使用webAppA進行身份驗證並顯示一些REST資源。它通過https 443部署在apache2中。每當我嘗試從webAppB發出http請求到webAppA請求失敗時,都將拋出下面打開的ssl異常。任何人都可以幫助我什麼可能是錯的?下面顯示了負責http連接的webAppB代碼片段。發出http請求時出現Openssl錯誤

/** 
* Check the username/password against the other webAppA$ 
*/ 
function webAppA_auth_check($username, $password) { 

    require_once("auth-functions.php"); 
    require_once("HTTP/Request2.php"); 

    $bare_base_url = localhost 
    // using basic authentication 
    $url = https://'.$username.':'.$password.'@'.$bare_base_url.':8443/app/ws/rest/v1/session'; 

    $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); 
    $request->setConfig(
     array(
      'ssl_verify_peer' => false, 
      'ssl_verify_host' => false, 
    ) 
); 
    try { 
    $response = $request->send(); 
    } catch (HTTP_Request2_Exception $e) { 
    echo 'Error: ' . $e->getMessage(); 
    var_dump($e->getMessage()); 
    exit(); 
    } 
} 

例外如下所示。

Error: Unable to connect to ssl://[email protected]:8443. Error: php_network_getaddresses: getaddrinfo failed: Name or service not knownstring(127) "Unable to connect to ssl://[email protected]:8443. Error: php_network_getaddresses: getaddrinfo failed: Name or service not known" 

PS:用戶名是虛擬和密碼是dummy123

+0

請啓用php.ini文件 SSL模塊'extension = php_openssl.dll' – user2092317

+0

我使用linux,所以我嘗試使用php_openssl。所以沒有成功:( – geekgugi

回答

1

簡單地使用Curl而不是HTTP請求

例如

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $response = curl_exec($ch); 
    print_r($response); 
+0

我刪除了所有HTTP/Request2.php。捲曲完美無缺:) – geekgugi

+0

Curl是開發者的好工具。其工作在所有平臺(Linux和Windows) –

相關問題