I need to make a Soap Request via PHP. To start from the beginning.. I have a html web page with a form and a button(not a submit btn). When the button is clicked an AJAX should POST two input values from the form to 'soap.php'. After that a Soap Request should be send to Web Service via php. Below is some of my code I have made, based on other examples I found on net.
AJAX
$('.button').on('click', function(){
alert('click!');
$.ajax({
type: 'POST',
data: {
nrTel: nrTel,
wiadomosc: code
},
url: 'soap.php',
success: function(response){
console.log(response);
alert('sukces');
},
error: function(response){
console.log(response);
alert('error');
},
});
});
PHP
<?php
$wsdl = 'http://89.234.196.188:81/SMS.asmx?WSDL';
$trace = true;
$exceptions = true;
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' =>$exceptions));
$xml_array['user'] = '';
$xml_array['pass'] = '';
$xml_array['phoneNumber'] = $_POST['telephone'];
$xml_array['message'] = $_POST['message'];
try
{
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->Send($xml_array);
}
catch (Exception $e)
{
echo "Error!";
echo $e -> getMessage ();
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
?>
The problem is that once I click button I get POST 500 (Internal Server Error).
Here is Soap requests...
POST /SMS.asmx HTTP/1.1
Host: 89.234.196.188
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://cpit.pl/Send"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Send xmlns="http://cpit.pl/">
<userName>string</userName>
<password>string</password>
<phoneNumber>string</phoneNumber>
<message>string</message>
</Send>
</soap:Body>
</soap:Envelope>
and response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendResponse xmlns="http://cpit.pl/" />
</soap:Body>
</soap:Envelope>
I don't have much experience in PHP and Soap so any help would by appreciated.