phpsoapsoap-clientnusoap

NuSoap Client Call works on localhost but not on Live Server


I have a Wordpress app that consumes an external API and connects to it via NuSoap Client request. I first developed this in localhost WAMP server, PHP 7.4, and got it working, but now I've migrated the project into a live server and it the same request doesn't work now.

This is my code PHP Nusoap Client code:

<?php
require_once(dirname(__FILE__) . '/nusoap.php');
ini_set('display_errors','On');

$userID = $_POST['UserId'];
$unitID = $_POST['UnitId'];
$serviceID = $_POST['ServiceId'];
$onlineUserID = $_POST['IdUserOnline'];

$soapClient = new nusoap_client('http://example-request-url.com?wsdl', 'wsdl');
var_dump($soapclient);//returns NULL

$error = $soapClient->getError();

if ($error) {
 die("client construction error: {$error}\n");
}    

$soapClient->soap_defencoding = 'UTF-8';
$soapClient->decode_utf8 = FALSE;

try{
   $params = array(
       'UserId' => $userID,
       'UnitId' => $unitID,
       'ServiceId' => $serviceID,
       'IdUserOnline' => $onlineUserID
   );
   //print_r($params);
   // array('parameters' => $params)
   $response = $soapClient->call('CreateSlip', array('parameters' => $params), '', '', false, true);  

   if ($soapClient->fault) {
       echo 'Error: ';
       print_r($response);
   }
   else{
       $error = $soapClient->getError();

       if ($error) {
           die("client construction error: {$error}\n"); //returns "client construction error: wsdl error: Getting http://example-request-url.com?wsdl 
                                                         //- HTTP ERROR: Couldn't open socket connection to server http://example-request-url.com?wsdl, Error (111): Connection refused
       }  
   }
   // $response = $soapClient->__soapCall('CreateSlip', $params);
   var_dump($response);//returns "bool(false)"
   $json_response = json_encode($response);
   echo $json_response;
   print_r(json_last_error_msg());
} catch (SoapFault $e){
   echo "Error: {$e}";//does not echo
}
?>

My live server has PHP 8.1, thought that might have been the issue but after changing the version to match the one from my WAMP server it still didn't work. The response I get from the API is false, meaning that the request was not correct. As I've mentioned before, on WAMP locahost this worked perfectly, any ideas on what might be wrong with my code?

Thanks in advance.


Solution

  • UPDATE on this.

    My issue was being caused because the PORT which the requests were being sent was closed. After exposing this to my hosting company they fixed it right away.