Page 1 of 1

An error when try to connect SOAP API in ver. 1.3

Posted: 26 Aug 2021, 04:43
by rsoft
Dear friends,
I try to connect to SOAP API via PHP for get response in JSON format with this code on Apache/2.4.23 (Win64) OpenSSL/1.0.2h PHP/7.0.10.
and I get: "Could not connect to host" error.
I'm newbie in web service usage and don't know what should I do?
please help me.
This is my code:

Code: Select all

<?php
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);

define('MANTISCONNECT_URL', 'https://localhost/peirang/api/soap/mantisconnect.php');
define('USERNAME', 'xxx');
define('PASSWORD', 'xxx');

parse_str($_SERVER['QUERY_STRING'], $args);
if (!isset($args['name'])) {
  die("No name specified.");
}
$function_name = $args['name'];
unset($args['name']);
$args = array_merge(
  array(
      'username' => trim(USERNAME),
      'password' => trim(PASSWORD)
  ),
  $args
);

try {
  $client = new SoapClient(null,array('uri'=> MANTISCONNECT_URL . '?wsdl','location'=> MANTISCONNECT_URL . '?wsdl','trace'=>True));
  $result = $client->__soapCall($function_name, $args);
} catch (SoapFault $e) {
  $result = array(
      'error' => $e->faultstring
  );
}
print json_encode($result);
?>