我有两个Web应用程序,只说webAppA和webAppB。 webAppA部署在运行在https 8443上的tomcat7中。它使用基本身份验证方案提供RESTful服务。 webAppB是基于php的Web应用程序,它使用webAppA进行身份验证并显示一些REST资源。它通过https 443部署在apache2中。每当我尝试从webAppB向webAppA发出http请求时,请求失败,在下面抛出open ssl异常。任何人都可以帮助我可能出错的地方吗?负责http连接的webAppB的代码片段如下所示。
/**
* 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://123@localhost:8443. Error: php_network_getaddresses: getaddrinfo failed: Name or service not knownstring(127) "Unable to connect to ssl://123@localhost:8443. Error: php_network_getaddresses: getaddrinfo failed: Name or service not known"
PS:用户名为dummy,密码为dummy123
答案 0 :(得分: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);