Https webservice php


Https webservice php

Keep get无法连接到主机这是我的服务器代码

  <?php 
  ini_set('soap.wsdl_cache_enabled',0);
  ini_set('soap.wsdl_cache_ttl',0);
  $soap_server = new SoapServer('Notification.wsdl');
  $soap_server->addFunction('Notify');
  function Notify($message)
  {
      return array('message' => $message);
  }
  $soap_server->handle();

  ?>

这是我的客户端代码,这就是引发错误的原因。端点是 https。WSDL 文件是本地文件。

    <?php

     $context = stream_context_create(array(
      'https' => array(
      'cafile' => 'APX_WS_API1.cer',
      'verify_peer' => true
      )
      ));
     $soap_client = new SoapClient('http://localhost:8888/Receiver/Notification.wsdl', 
      array('stream_context' => $context,'local_cer' => 'APX_WS_API1.cer'));
     try{
     $result = $soap_client->__soapCall('Notify',array('message' => 'Hello World'));
     echo $result;
      }catch(SoapFault $e){
      echo "Error: " . $e->faultstring;
      }

         ?>

有人可以告诉我我做错了什么。提前致谢

您的证书有效吗?试试这个选项:

$context = stream_context_create(array(
            'ssl' => array(
                'verify_peer' => false,
                'allow_self_signed' => true
            )
        ));

如果它有效,则意味着您的证书无效。