I am trying to do a soap call and I keep getting the following error:
looks like we got no XML document
EDIT error message
here's an example that works fine in my SOAP UI
Here's my array that I send to my soapCall:
$params = [
'id' => '0000002721',
'options' => [
'returnAttachments' => 'false',
'returnPictures' => 'false',
'returnContract' => 'false'
]
];
Here is the code how I make the soap call
try {
$options = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$context = stream_context_create($options);
$soapClient = new SoapClient(__DIR__ . '/Soap.wsdl', [
'stream_context' => $context,
'login' => 'login',
'password' => 'password',
'trace' => 1,
'exceptions' => true,
]);
$soapClient->__setLocation('url');
$this->soapClient = $soapClient;
} catch (\SoapFault $e) {
var_dump($e); exit;
}
try {
$result = $this->soapClient->__soapCall('getMaintenanceObject', $params);
} catch (\SoapFault $e) {
var_dump($e); exit;
}
SoapClient can be not very expressive when it comes to displaying the errors, add this:
var_dump($this->soapClient->__getLastRequestHeaders());
var_dump($this->soapClient->__getLastResponseHeaders());
Related
I am using standard SoapClient class to make requests to the payment server.
$context = stream_context_create([
'http' => [
'follow_location' => 0,
],
]);
$options = [
'uri' => 'urn:PaymentServer',
'location' => 'http://localhost:8001/index.php',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true,
'soap_version' => SOAP_1_1,
'stream_context' => $context,
'connection_timeout' => 50,
];
$soapClient = new SoapClient(null, $options);
try {
var_export($soapClient->GetPayment([]));
} catch (Throwable $e) {
echo $e->getMessage();
var_export($soapClient->__getLastResponse());
}
Script http://localhost:8001/index.php contains following code
header('Location: http://example.com', true, 302);
exit;
I expect empty result, but the actual output contains HTML from example.com
I have tried get_file_contents function with the same stream context:
var_export(file_get_contents('http://localhost:8001/index.php', false, $context));
And I have got empty string.
What SoapClient or stream context option should be set to prevent redirects?
I'm trying to consume the "search" function of the Brazilian CADSUS service, but I get the following error:
"Forced circuit exception";
Right below, I have the following code, which uses Laravel 5.6 and PHP 7.1
Route::get('/ws/teste', function () {
try {
$opts = array(
'http' => array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$wsdlUrl = 'https://servicoshm.saude.gov.br/cadsus/CadsusService/v5r0?wsdl';
$soapClientOptions = array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE,
'Username' => '*****',
'Password' => '*****'
);
$client = new SoapClient($wsdlUrl, $soapClientOptions);
$parameters = array(
'CNESUsuario' => array(
'CNES' => '6963447',
'Usuario' => 'LEONARDO',
'Senha' => ''
),
'FiltroPesquisa' => array(
'nomeCompleto' => 'SERGIO ARAUJO CORREIA LIMA',
'tipoPesquisa' => 'IDENTICA'
),
'higienizar' => 0
);
$result = $client->pesquisar($parameters);
print_r($result);
}
catch(\Exception $e) {
echo $e->getMessage();
} });
I would appreciate any help. Thanks in advance
From SOAP response:
[cvc-minLength-valid: Value '' with length = '0' is not facet-valid with
respect to minLength '1' for type '#AnonType_SenhaCNESUsuarioType'.,
cvc-type.3.1.3: The value '' of element 'ns1:Senha' is not valid
So, Senha can't be empty string.
I am trying connect to web service with local cert in php. Soapclient return this error: Warning: SoapClient::SoapClient(): Unable to set local cert chain file ***.p12'; Check that your cafile/capath settings include details of your certificate and its issuer in url on line 226. This cert hasn't cafile... What can i do? My code is this:
$wsdl = 'url';
try {
$soapClient = new SoapClient($wsdl, array(
"trace" => 1,
"exceptions" => false,
"endpoint" => $wsdl,
"soap_version" => SOAP_1_1 ,
"location" => "url",
'stream_context' => stream_context_create(array(
'ssl' => array(
"verify_peer" => false,
'verify_peer_name' => false,
'allow_self_signed' => false,
'ciphers' => 'DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA',
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
"local_cert" => '***.p12',
"passphrase" => ******,
)
))
)
);
echo "<pre>";
print_r($soapClient);
echo "</pre>";
} catch(Exception $e) {
echo "<pre>";
print_r($e);
echo "</pre>";
}
In Java, it is necessary use truststore but i don`t know to do equivalent in php.
Any help would be much appreciated. Thanks in advance.
I'm attempting to connect with a WS via Soap and struggling with a content type error when I call the method: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'
Below is my code, reducing number of params and hiding url, user and password.
The error happens when I call the ClientRegist() function. I'm convinced I have to pass $params in a different way, but can't find an example anywhere.
$url = 'http://---';
$ctx_opts = array(
'http' => array(
'header' => 'Content-Type: application/soap+xml'
),
'username' => '---',
'password' => '---',
'trace' => true,
'exceptions' => true
);
$ctx = stream_context_create($ctx_opts);
$client = new SoapClient($url, array('stream_context' => $ctx));
$params = array(
'Cardnumber' => $number,
'Name' => $name
);
try {
$client = new SoapClient($url, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->ClientRegist($params);
}
catch (Exception $e) {
echo "Error!<br>";
echo $e -> getMessage ().'<br>';
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
Try SOAP version 1.2. Its default Content-Type is application/soap+xml
<?php
// ...
$client = new SoapClient(
$url,
array(
'soap_version' => SOAP_1_2, // !!!!!!!
'stream_context' => $ctx
)
);
I have this code to start Zend Cache , and I set the try cache exception to cancel Zend Cache if an error accorded during the process, but it does not work and does not print the error inside catch Exception.
$frontendOptions = array(
'lifetime' => $cacheTime,
'content_type_memorization' => false,
'default_options' => array(
'cache' => true,
'make_id_with_cookie_variables' => false,
'make_id_with_session_variables' => false,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_files_variables' => true,
'cache_with_cookie_variables' => true,
'tags' => $cacheTag,
),
'regexps' => array(
'$' => array('cache' => true),
)
);
$backendOptions = array('cache_dir' => '/var');
$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
try {
$cache->start();
} catch (Exception $exc) {
echo $exc->getMessage();
}
and I tried the $cache->cancel() without any result.
Thanks