【发布时间】:2017-07-29 09:13:26
【问题描述】:
我正在尝试连接到 Azure API。我对此有点陌生。我正在使用示例中给出的 php 代码。我在本地服务器上使用 wamp。
我已经在 localhost 上配置了 SSL,这样我就可以打开 https://www.wamphelpers.dev/faces.php
但是我不断收到以下错误:
Failed to enable crypto stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in <b>C:\wamp\bin\php\php5.5.12\pear\HTTP\Request2\Adapter\Socket.php
My code is below:
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';
$request = new Http_Request2('https://southeastasia.api.cognitive.microsoft.com/face/v1.0/persongroups/{personGroupId}');
$url = $request->getUrl();
$headers = array(
// Request headers
'Content-Type' => 'application/json',
'Ocp-Apim-Subscription-Key' => 'keygoeshere',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'personGroupId' => 'heroes',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_PUT);
// Request body
$request->setBody("heroes");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
根据我的阅读,这是一个证书问题,我检查了我的 php 设置并确保它指向正确的文件。 输出如下:
OPENSSL_CONF C:\OpenSSL-Win32\bin\openssl.cfg
我读了一点,似乎我可以使用 context_options 通过将验证对等设置为 false 来禁用 PHP 中的 SSL 检查。
但是我如何使用它来点击 URL。
以下是 API 参考链接。
【问题讨论】: