我有两个Web应用程序,只是说webAppA和webAppB。webAppA部署在运行于https 8443的tomcat7中。它使用基本身份验证方案提供RESTful服务。webAppB是基于php的Web应用程序,它使用webAppA进行身份验证并显示一些REST资源。它通过https 443部署在apache2中。每当我尝试从webAppB向webAppA发出http请求时,都无法在下面引发open ssl异常。谁能帮我什么可能出问题了?来自webAppB的负责http连接的代码段如下所示。
/**
* 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:用户名是哑元,密码是哑元123
只需使用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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句