Eric Evans
Eric Evans

Reputation: 670

Https webservice php

Keep getting could not connect to host this is the server code that I have

  <?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();


  ?>

And this is my client code which is what is throwing the error. The endpoint is https. the wsdl file is local.

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


         ?>

Could someone please tell me what am i doing wrong. Thanks in advance

Upvotes: 0

Views: 1376

Answers (1)

Vincent
Vincent

Reputation: 555

Is your certificate valid? Try this option:

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

If it works that means your cert is invalid.

Upvotes: 1

Related Questions