im using php 5.6 the thing is that im trying to catch php_network_getaddresses exception, but it gives me a fatal error.
Im trying to shut error_reporting(0) but it only reloads the page
I tried to to this too
error_reporting(0);
try {
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$opts = array(
'http' => array(
'header' => "apikey: TokenApi $token",
)
);
$context = stream_context_create($opts);
$client = new \SoapClient($wsdl
, [
'stream_context' => $context,
'exception' => 0,
'trace' => 1
]);
}
catch (SoapFault $e) {
//echo $e->faultstring.'<br>asdasd';
trigger_error($e->getMessage());
if (strpos($e->faultstring, 'failed to load external entity')) {
$fecha_hora = "sin conexion";
return $fecha_hora;
//echo "The string 'lazy' was found in the string";
}
}
im not using xdebug and soap is enabled on php.ini
How can i catch this Fatal error to prevent the script die?
Im using cakephp 2.3 too, but i think this is not a problem from the framework.
Related
I made a research on web but I couldn't find the exact answer for my question. I am trying to make a request to a SOAP service. I can get a proper response when I try with SOAPUI but I can't get anything when I try it with PHP.
Here is a screenshot of SOAPUI: (Backup URL: http://i.hizliresim.com/qGaOOd.png)
Here is my PHP code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$wsdl = "http://www.estes-express.com/shipmenttracking/services/ShipmentTrackingService?wsdl";
$options = array(
'auth' => array(
'user' => 'myuser',
'password' => 'mypass'
)
);
$request = array(
'search' => array(
'requestID' => '0841824923',
'pro' => '0841824923'
)
);
$client = new SoapClient($wsdl, $options);
echo '<pre>'.print_r($client,true).'</pre>';
try{
$response = $client->__soapCall('trackShipments', array($request));
print_r($response);
} catch(SoapFault $ex){
echo $ex->getMessage();
}
print "\n";
When I run this script, it returns this error: "java.lang.NullPointerException"
Any solutions? Thanks in advance.
I have a soapClient call that works fine with PHP 5.6 (RH6). We are upgrading the system to PHP 7 (RH7 with the same configuration as the previous one) but the same call does not work.
This is my code
$wsdlUrl = "https://THE_URL_I_AM_CALLING/repository/soap/2.1?wsdl";
$sslClientCert = "../../app/config/ssl/ssl_cert.crt";
$sslClientKey = "../../app/config/ssl/ssl_cert.key";
$proxy = 'proxy_http';
$port = 8080;
$contextOptions = [
'ssl' => [
'local_cert' => $sslClientCert,
'local_pk' => $sslClientKey,
'SNI_enabled' => true,
'SNI_server_name' => 'THE_URL_I_AM_CALLING'
]
];
$options= [
"soap_version" => SOAP_1_2,
"features" => SOAP_SINGLE_ELEMENT_ARRAYS,
"stream_context" => stream_context_create($contextOptions),
'proxy_host' => $proxy,
'proxy_port' => $port
];
$client = new SoapClient($wsdlUrl, $options);
try {
// execute the search
$searchResults = $client->searchDocuments([
"text" => "myText",
"hint" => "document"
]);
}
catch (Exception $e) {
echo $e->getMessage();
}
the error I get under PHP 7 is
PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host
if I make the call using CURL it works.
I would rather use clientSoap to make my life easier.
I found the solution. Posting it here so no other soul on earth needs to go through this ordeal.
According to the documentation
http://php.net/manual/en/context.ssl.php#context.ssl.sni-server-name
SNI_server_name (string):
If set, then this value will be used as server name for server name indication. If this value is not set, then the server name is guessed based on the hostname used when opening the stream.
Note: This option is deprecated, in favour of peer_name, as of PHP
5.6.0.
After changing:
'SNI_server_name' => 'THE_URL_I_AM_CALLING'
with
'peer_name' => 'THE_URL_I_AM_CALLING'
It works.
Using Plesk 12.5 and PHP 7.0.2 I get the error:
SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://<IP ADDRESS>:9443/Configuration?wsdl' : failed to load external entity "https://<IP ADDRESS>:9443/Configuration?wsdl" in <PHP FILE>:51 Stack trace: #0 <PHP FILE>(51): SoapClient->SoapClient('https://<IP FILE>', Array) #1
It works using PHP 5.3 from the OS, but and PHP from Plesk I get the above error.
PHP-SOAP, XML, is installed.
The code I am using is:
try {
$configClient = new soapclient("https://{$node["host"]}:{$node["port"]}/Configuration?wsdl",
array('login' => $node["user"],
'password' => $node["pass"],
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
)
);
$configResponse = $configClient->enableALLProductFeatures();
} catch (SoapFault $exception) {
echo "Problem..... : ";
echo $exception;
}
Resolved by stream_context options. My code now looks like the following:
$context = stream_context_create(array(
'ssl' => array('verify_peer' => false, 'verify_peer_name'=>false, 'allow_self_signed' => true)
));
try {
$configClient = new soapclient("https://{$node["host"]}:{$node["port"]}/Configuration?wsdl",
array('login' => $node["user"],
'password' => $node["pass"],
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'stream_context' => $context
)
);
$configResponse = $configClient->enableALLProductFeatures();
} catch (SoapFault $exception) {
echo "Problem..... : ";
echo $exception;
}
Try debug your connection with curl:
curl -v --user "<login>:<password>" --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:<action>" --data #<file_name> <url_of_the_soap_web_service>
Using SoapClient in PHP, I've come across a problem I have not been able to find a solution to.
I'm using a local copy of the wsdl file and I am using this setup:
$this->client = new \SoapClient(__DIR__ . '/../../some.wsdl',
array(
'proxy_host' => $ip,
'proxy_port' => $port,
'trace' => 1,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
This gives error : "Forbidden" when calling :
$this->client->__call($method, $params)
I have tried calling __getFunctions()
$this->client->__getFunctions()
that gives the list of all function in my WSDL file.
Am I missing something?
Debug code with like this :
<?php
try{
$client = new SoapClient($wsdl, $params);
$out = $client;
}catch(Exception $e){
$out = array('error' => $e, 'libxml' => libxml_get_last_error());
}catch(SoapFault $s){
$out = array('error' => $s, 'libxml' => libxml_get_last_error());
}
var_dump($out);
exit();
Getting the below error when trying to make a SOAP call using HTTPS.
Below is the code. I have tried different ways around it with no luck.
Link is http://dev.jp-websolutions.co.uk/teletrac/getsafetydata/test
The error that I'm seeing is SoapFault exception: [soap:Receiver] Server was unable to process request. ---> Object reference not set to an instance of an object.
This is what I'm using right now.
header("Content-Type: text/plain");
$params = array(
"UserName" => "xxx",
"Password" => "xxx",
);
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA')
);
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("https://onlineavl2dev-uk.navmanwireless.com/OnlineAVL/API/v1.3/Service.asmx?wsdl", array('trace' => 1, 'soap_version' => SOAP_1_2, "encoding"=>"ISO-8859-1",
'stream_context' => stream_context_create($opts)));
#print_r($client); die;
#$response = $client->DoLogin($params);
//print_r($client->__getFunctions());
//print_r($client->__getTypes());
try {
echo "<pre>\n";
$result = $client->DoLogin(array(
"UserName" => "xxx",
"Password" => "xxx",
));
print_r($result);
echo "\n";
}
catch (SoapFault $exception) {
echo $exception;
}
print_r($response); die;