简体   繁体   English

尝试连接到Azure API时发生SSL错误

[英]SSL error when trying to connect to Azure API

I am trying to connect to Azure API.I am kinda new to this.I am using the php code given in the samples.I am using wamp on my local server. 我正在尝试连接到Azure API。我对此有点陌生。我正在使用示例中给出的php代码。我在本地服务器上使用了wamp。

I have configured SSL on localhost so that I am able to open https://www.wamphelpers.dev/faces.php 我已经在本地主机上配置了SSL,以便能够打开https://www.wamphelpers.dev/faces.php

However I keep getting the error below: 但是我不断收到以下错误:

 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;
}

?>

From what I have read it is a certificate issue and I have checked my php settings and made sure it is pointing to the right file. 从我阅读的内容来看,这是一个证书问题,我已经检查了我的PHP设置,并确保它指向正确的文件。 out is below: 下方是:

OPENSSL_CONF    C:\OpenSSL-Win32\bin\openssl.cfg

I read a little and it seems I can disable SSL check in PHP using the context_options by making verify peer to false. 我读了一点,似乎可以通过使verify peer为false来使用context_options禁用PHP中的SSL检查。

But how do I use it to hit the URL. 但是我怎么用它来打URL。

Below is the link for the API reference. 以下是API参考的链接。

Just point HTTP/Request2 to use a CA bundle, as instructed here . 只需按此处指示HTTP/Request2指向使用CA捆绑包即可。

ssl_cafile

Certificate Authority file to verify the peer with (use when ssl_verify_peer is TRUE). 用于验证对等方的证书颁发机构文件(当ssl_verify_peer为TRUE时使用)。 You can use eg cURL's CA Extract tool to get such a file. 您可以使用例如cURL的CA提取工具来获取此类文件。

$request = new HTTP_Request2();
$request->setConfig(array(
    'ssl_cafile' => '/path/to/cacert.pem'
));

The remote certificate can now be verified against the complete chain. 现在可以对照完整的链来验证远程证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM