php WSDL (SOAP) client - php

I have a problem co communicate with SOAP service in php:
My code for client:
$url = "https://XXXX.com/DataService.svc?singleWsdl";
$client = new SoapClient($url);
var_dump($client->__getFunctions()); // ExportScheduleData(ExportScheduleData $parameters)
$aclient->ExportScheduleData(array());
I got:
Uncaught SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.
change soap version to 1.2:
$client = new SoapClient($url, array('soap_version' => SOAP_1_2));
And request could not be completed: when I refresh page it still in loaging state - any errors or so.
===== update =====
Looks like service use WS-Security. They provide certificate file, but:
Warning: SoapClient::SoapClient(): Unable to set local cert chain file `C:\xampp\htdocs\workspace\sandbox.dev\public\sandbox.cer'; Check that your cafile/capath settings include details of your certificate and its issuer in C:\xampp\htdocs\workspace\sandbox.dev\public\sandbox.php on line 34

Resolved.
Write a Java application for ws-secutity check and and query java app from php script. I use java tcp server.

Related

Laravel 5.8.* using GuzzleHttp on production

I'm using GuzzHttp in my laravel project to post some data to an API. In my local enviroment I have to to create my client with the cacert.pem file verification like this:
$client = new \GuzzleHttp\Client(['verify' => 'C:\wamp64\bin\php\php7.2.14\cacert.pem']);
But I can't do so on my shared hosting. So, removing that verification:
$client = new \GuzzleHttp\Client();
Results on an internal server error:
[2019-06-11 15:17:10] local.ERROR: GuzzleHttp\Exception\ServerException: Server error: `POST https://pruebas2.mayoristaseguridad.es/tiendaseguridad/02-ConectorLaravelPrestashop/ConectorCategorias.php` resulted in a `500 Internal Server Error` response in /home/admin/web/iberoseguridad.eu/public_html/csv_products/vendor/guzzle/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Is there a way to fix this error?
Not sure if this will help, here it goes anyways
// Disable validation entirely (don't do this!).
$client->request('GET', '/', ['verify' => false]);
Guzzle verify api
This ended up being a remote server error, not mine. I just had to communicate that error with the server's maintainer and now it works just fine.

Services_Twilio_TinyHttpException error PHP

I been trying to seen SMS messages from Twilio but get the error message.
I have added a path to a new curl.cainfo in the php.info
curl.cainfo = c:\wamp\certs\cacert.pem
yet I still was getting an error.
ERROR MESSAGE WAS:
Fatal error: Uncaught exception 'Services_Twilio_TinyHttpException' with message 'SSL certificate problem: self signed certificate in certificate chain' in C:MYPATH\twilio-php-master\twilio-php-master\Services\Twilio\TinyHttp.php on line 119
This is the PHP code:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require ('C:/wamp/www/Services/Twilio.php'); // Loads the library
$sid = "Axxxxxxxxxxxxxxxxxxxxxxx9";
$token = "8xxxxxxxxxxxxxxxxxxxxxxx2";
$http = new Services_Twilio_TinyHttp(
'https://api.twilio.com',
array('curlopts' => array(
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
)));
$client = new Services_Twilio($sid, $token, "2010-04-01", $http);
$sms = $client->account->sms_messages->create("+1480xxxxx", "+1520xxxxx", "HELP please?! I love you <3", array());
echo $sms->sid;
?>
Im using Windows 8, and the the curl version:cURL Information 7.36.0 is enabled
should I update the curl stated in https://github.com/twilio/twilio-php/blob/master/docs/faq.rst
What am I doing Wrong?
Twilio Customer Support here!
Did you update cURL as mentioned earlier?
https://github.com/twilio/twilio-php/blob/master/docs/faq.rst#ssl-validation-exceptions
It should resolve the issue, if not ping help#twilio.com an email and we can look into it.
Make same changes in php.ini inside apache bin folder.
"curl.cainfo = c:\wamp\certs\cacert.pem"
Restart the service.

PHP - Cannot get SOAP server to work

I have written a very simple SOAP Server to check access to the server but I'm getting an error.
The server is a brand new VM of Windows Server 2008R2 (which I installed today to check this) I then installed WAMP which is working correctly. I think the issue is more of a configuration one but I'm no expert from here so need some help finding it.
I have enabled SOAP in WAMP. The WSDL is fine, I have checked it on a hosted server and it works as expected along with the server and client php files.
The error received at the client:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't load from './Soaptest.wsdl' : failed to load external entity "./Soaptest.wsdl" in
C:\wamp\www\Connector\Testing\c20\c20simpleClient.php:7
Stack trace: #0 C:\wamp\www\Connector\Testing\c20\c20simpleClient.php(7):
SoapClient->SoapClient('./c20simpleSoap...') #1 {main} thrown in
C:\wamp\www\Connector\Testing\c20\c20simpleClient.php on line 7
The Soap Server:
function Test(){
return true;
}
$server = new SoapServer("Soaptest.wsdl");
$server->addFunction("Test");
$server->handle();
The client (Line 6+):
$url = "./Soaptest.wsdl";
$client = new SoapClient($url);
echo "client created<br>";
$result = $client->Test();
echo "<hr>Method Test: <pre>".(string)$result."</pre>";
Aside from enabling soap in the php config, is there anything I need to do in Apache or php to enable SOAP?

Goutte - TLSv1 protocol version error

I'm using Goutte to get a page on a web server using an SSL certificate. Whenever I try to get this page the the following exception is thrown:
Uncaught exception 'Guzzle\\Http\\Exception\\CurlException' with message
'[curl] 35: error:1407742E:SSL
routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
[url] https://somesite.com
I have been looking online for this type of error. It seems that this error happens when there is a handshake failure. The server seems to support TLSv1 and the client uses SSL23.
I'm not sure if this assessment is correct nor do I know how to correct it.
This is the code I'm currently using:
<?php
use Goutte\Client;
$client = new Client();
$guzzle = $client->getClient();
$guzzle->setConfig(
array(
'curl.CURLOPT_SSL_VERIFYHOST' => false,
'curl.CURLOPT_SSL_VERIFYPEER' => false,
)
);
$client->setClient($guzzle);
$crawler = $client->request('GET', 'https://somesite.com'); // IT FAILS HERE
UPDATE:
NOTE: I started getting a few weeks ago a similar error, so I thought I would update the question and answer as they are related.
I got a similar error:
[curl] 35: Unknown SSL protocol error in connection to website.com:443
I found the answer to this problem in the blogpost "Fixing SSL Handshake with PHP5 and Curl"
This error can happen in some operating systems but not in all making it a hard issue to replicate. I am currently using Ubuntu 12.04 in my development environment.
Thankfully this is something that can be addressed at the code level like this:
use Goutte\Client;
$client = new Client();
$guzzle = new GuzzleClient('https://somesite.com', array(
'curl.options' => array(
'CURLOPT_SSLVERSION' => 'CURL_SSLVERSION_TLSv1',
)
));
$client->setClient($guzzle);
$crawler = $client->request('GET', 'https://somesite.com');
UPDATE:
For the solution for the message
[curl] 35: Unknown SSL protocol error in connection to website.com:443
was a bit tricky to resolve as the message gives no indication of what is going on.
This GitHub issue pointed me in the right direction tho. There are multiple versions of the CURLOPT_SSLVERSION I can use (of course!), but these include v1.0, v1.1, and v1.2! See the curl_setopt for more information.
For this particular error I ended up using the following code:
$guzzle = new GuzzleClient('https://somesite.com', array(
'curl.options' => array(
'CURLOPT_SSLVERSION' => 'CURL_SSLVERSION_TLSv1_1',
)
));
The site I was trying to connect to would not accept any other option including CURL_SSLVERSION_TLSv1.

php soap wsdl connection error

I have been trying to connect to a web service which I previously had set up using a soap request in PHP, like so:
$client = new SoapClient($this->config->item('WSDL'));
$response = $client->Login(array('email' => $this->input->post('email'), 'password' => $this->input->post('password')));
this worked when the WSDL url ended in asmx?WSDL but now its a different url ending in .xml and it doesn't work...I keep getting the following error: "PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in..."
Can anyone help me please? It is hurting my head, thanks!
URL of WSDL can be ended with anything. Try to echo your WSDL URL and load it by browser.
$client = new SoapClient(exit($this->config->item('WSDL')));

Categories