I am trying to make an API request which is on a remote windows 2008 server R2, from my Zend client, and everytime I try to do it, I get the following errors:
Message: Unable to enable crypto on TCP connection wvm024.dei.isep.ipp.pt
And: Previous exceptions:
ErrorException
File:
C:\Program Files (x86)\Zend\ZendServer\data\apps\http__default__\0\TukPorto\1.0.0_118\TukPorto\vendor\zendframework\zendframework\library\Zend\Http\Client\Adapter\Socket.php:281
Message:
stream_socket_enable_crypto(): Peer certificate CN=wvm024.wvdom024.dei.isep.ipp.pt' did not match expected CN=
wvm024.dei.isep.ipp.pt'
The code I have for that is the following:
$username = WebApiServices::$username;
$password = WebApiServices::$password;
$enderecoBase = WebApiServices::$enderecoBase;
$httpClientOptions = array(
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'persistent'=>false,
'sslverifypeer' => false,
'sslallowselfsigned' => true,
'sslusecontext'=>true,
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true,
'capture_peer_cert' => true,
),
'useragent' => 'Feed Reader',
);
$client = new Client($enderecoBase . '/Token');
$client->setOptions($httpClientOptions);
$client->setMethod(Request::METHOD_POST);
$data = "grant_type=password&username=$username&password=$password";
$len = strlen($data);
$client->setHeaders(array(
'Content-Type' => 'application/x-www-form-urlencoded',
'Content-Length' => $len
));
$client->setOptions([
'sslverifypeer' => false,
]);
$client->setRawBody($data);
$response = $client->send();
$body = Json::decode($response->getBody());
if (! empty($body->access_token)) {
if (! isset($_SESSION)) {
session_start();
}
$_SESSION['access_token'] = $body->access_token;
$_SESSION['username'] = $username;
return true;
} else
return false;
CN=wvm024.dei.isep.ipp.pt
. – Crypt32