I am very new to PHP and weak in programming.
I need to create a web service using PHP.
The main purpose is to allow user to enter their info and validate it at the backend database.
User enter their info in HTML in an array of
$_SESSION['ctform'][]
detail.php (client)
$wsdl = "http://localhost/detail_logic.php";
$client = new soapclient($wsdl);
$response = $client->_call('process_si_contact_form', array($_SESSION['ctform']));
detail_logic.php (server)
function process_si_contact_form()
{
//Process and validate the info
//Data base connection
}
$ss = new SoapServer(null, $_SESSION['ctform']);
$ss->addFunction("process_si_contact_form");
$ss->handle();
I have many error like:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/detail_logic.php'
Please help and Thank you.
I think, You need a wsdl file for creating a Soap based server, So client can be communicate to it. Also client will communicate through wsdl file not directly with Url. See http://php.net/manual/en/sca.examples.understanding-wsdl.php and http://in1.php.net/manual/en/soapclient.soapclient.php
Related
I'm deploying Twilio on my website following Javascript Quickstart: https://www.twilio.com/docs/voice/client/javascript/quickstart
I receive multiple calls and register info to my database, if I don't want my Twilio client answers an incoming call, I can hangup using the callSid according to this url: https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-update-a-call-resource-to-end-the-call&code-language=PHP&code-sdk-version=5.x
Code:
<?php
include "../../../twilio_client/vendor/autoload.php";
use Twilio\Rest\Client;
$callsid = $_POST['callsid'];
// put your Twilio API credentials here
$accountSid = 'AC2XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$authToken = '67XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$twilio = new Client($accountSid, $authToken);
$call = $twilio->calls($callsid)->update(array("status" => "canceled"));
$calla = $twilio->calls($callsid)->fetch();
$parentCall = $calla->parentCallSid;
$call = $twilio->calls($parentCall)->update(array("status" => "completed"));
?>
This works great, so in the same way but If I want to answer an incoming call using the callSid I tried with this according to this url: https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-update-a-call-in-progress-with-twiml
Code:
<?php
include "../../../twilio_client/vendor/autoload.php";
use Twilio\Rest\Client;
$callsid = $_POST['callsid']; //callSid
$usrclient = $_POST['usrclient'];//client connected to receive calls
// put your Twilio API credentials here
$accountSid = 'AC2XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$authToken = '67XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$twilio = new Client($accountSid, $authToken);
$call = $twilio->calls($callsid)->update(array("twiml" => "<Response><Dial><Client>".$usrclient."</Client></Dial></Response>"));
?>
But it doesn't work, It shows me this error:
[Wed Jan 15 23:14:06.493068 2020] [:error] [pid 30189] [client 190.239.139.220:18718] PHP Fatal error: Uncaught exception 'Twilio\\Exceptions\\RestException' with message '[HTTP 400] Unable to update record: Call is not in-progress.
How can I fix it?
I'd like your help.
Thanks.
You can return TwiML without modifying the call, since the call isn't established.You returned TwiML in the Application SID Voice URL to the website side Twilio Client (twilio.js), directing it to dial your client.
You are getting a HTTP 400 error which is a BAD REQUEST. Twilio defines it as: The data given in the POST or PUT failed validation. Inspect the response body for details. https://www.twilio.com/docs/usage/your-request-to-twilio
And you have the error: call is not in-progress
As far as I can tell, your $_POST['usrclient'] is not correct. Check your POST to ensure it is valid.
You could also test your script by changing the Twiml to something simple and calling it yourself. Then you'll know if it's the script or the usrclient
<Response><Say>Ahoy there</Say></Response>
I am attempting to create a user on my Chef Server through the Chef Server API. I am currently using a PHP wrapper for the API interface which can be found here.
I understand that in order to create a user using the API, you must provide the pivotal.pem file as well as the pivotal username.
Here is a snippet of my PHP code that I am using:
// ENVIRONMENT VARIABLES
// The URL for the Chef Server
$server = "mycompany.com";
// The name used when authenticating
$client = 'pivotal';
// The location of the file which contains the client key
$key = "../../../pivotal.pem";
// The version of the Chef Server API that is being used
$version = "12.0.2";
// Create a Chef object
$chef = new Chef($server, $client, $key, $version);
// API Request
$createUserRequest = array("name"=>$displayName, "display_name"=>$displayName, "email"=>$emailAddress, "password"=>$password);
$createUserRequest = json_encode($createUserRequest);
$chef->post('/users/', $createUserRequest);
Here is the reponse that I receive from the server:
Fatal error: Uncaught exception 'Exception' with message 'Invalid signature for user or client 'pivotal'' in C:\Workspace\SA_SSAF\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php:187
Stack trace:
#0 C:\..\..\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php(70): Jenssegers\Chef\Chef->api('/users/', 'POST', '{"name":"entra"...')
#1 C:\..\..\app\plugin\CHEF\controller\chefEnrollUser.php(55): Jenssegers\Chef\Chef->post('/users/', '{"name":"entra"...')
#2 {main}
thrown in C:\..\..\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php on line 187
If I try and perform a GET request using the same configuration, I receive a successful response.
Any clues as to why something like this may be happening?
Thanks
I want to verify a signature for a soap request on a soap server implemented in php.
The server code:
$Server = new SoapServer();
$d = new DOMDocument();
$d->load('php://input');
$s = new WSSESoapServer($d);
try {
if($s->process()) {
// Valid signature
$Server->handle($s->saveXML());
} else {
throw new Exception('Invalid signature');
}
} catch (Exception $e) {
echo "server exception: " . $e;
}
The error:
exception 'Exception' with message 'Error loading key to handle Signature' in /<path>/wse/src/WSSESoapServer.php:146
I have implemented a Client to sign SOAP requests using this library: https://github.com/robrichards/wse-php. There are no examples of how to implement the server...
How do I load the public key to check the signature?
[Edit]
I have now been able to load the supplied key using
$key = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'public'));
$key->loadKey(CERT, true);
I am no longer getting an error message when validating the signature:
$x = new XMLSecurityDSig();
$d = $x->locateSignature($soapDoc);
$valid = $x->verify($key);
However, $valid is always false. I have no idea if it's because the key is loaded wrong or is actually invalid. I can find very little information on implementing a SOAP server with PHP and no information on implementing a SOAP server that relies on checking a signed request.
CLARIFICATION
My client talks to a remote web service and gets an acknowledgement.
Then the remote server takes some time to process my request.
A remote client (that I have no control over) then makes a request to
my service.
The last step is where I have trouble verifying the signature
Well anyways, your first approach looks fine to me, my server has the same structure. Unfortunately, WSSESoapServer does not inherit from SoapServer, thus is not really an SoapServer, but rather a SoapSignatureValidator and should be called like that. It would be easily possible to correct that behaviour, that one would not need a separate SoapServer instance (should be transparent and automatically).
<?php
require 'soap-server-wsse.php';
try {
// get soap message
$xmlSoap = DOMDocument::load('php://input');
// validate signature
$validateSignature = new WSSESoapServer($xmlSoap);
if(!$validateSignature->process())
file_put_contents("log.txt", "soapserver: SIGNATURE VALIDATION ERROR - CONTINUING WITHOUT SIGNATURE\n", FILE_APPEND);
//throw new Exception('Invalid Signature'); # this would cancel the execution and not send an answer
$sServer = new SoapServer($wsdl);
// actually process the soap message and create & send answer
//$sServer->setClass() or setObject() or set setFunction()
$sServer->handle($validateSignature->saveXML());
} catch (Exception $fault) {
file_put_contents("log.txt", "soapserver soapfault: ".print_r($fault, true), FILE_APPEND);
}
?>
Dear Supporter,
$data=array(
"themeName"=>"gghg"
);
$adapter = new Zend_Http_Client_Adapter_Curl();
$adapter->setConfig($curlOption);
//instantiate the http client and add set the adapter
$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");
$client->setAdapter($adapter);
//add the post parameters from our config file (the authentication part)
$client->setParameterPost($data);
//perform the post, and get the response
$response = $client->request(Zend_Http_Client::POST);
Error :
Fatal error: Uncaught exception 'Zend_Uri_Exception' with message 'Invalid URI supplied' in /var/www/html/ursify/Source/ursify.com/library/Zend/Uri/Http.php:
I am trying to create client object "$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");"
Where i am doing wrong ? Help me
Seems everything fine. I've tested your code and there are no errors except timeout in cUrl call. I've tested with ZF 1.12.7
I am trying to create a website that retrieves data from a Web Service using the site API.
The 'nuSOAP' PHP library seems to be a perfect way to go about this and so I have been trying to run through a basic tutorial by Scott Nichol called 'Introduction to NuSOAP'.
Here is the code for server.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
...and here is the code for the client.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'John'));
// Display the result
print_r($result);
?>
I have 'XAMMP' installed and so when I call up client.php via the browser it should bring up a basic page that says 'Hello, John' but instead I get the following error message:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '.../server.php' : Start tag expected, '<' not found in C:\xampp\htdocs\beehive\client.php:7 Stack trace: #0 C:\xampp\htdocs\beehive\client.php(7): SoapClient->SoapClient('http://...') #1 >{main} thrown in C:\xampp\htdocs\beehive\client.php on line 7
I figured I should be loading the client page rather than the server, but if I load server.php then I get the error message 'This service does not provide a Web description'.
I have followed the tutorial exactly and can't figure out why it's throwing this error; can anyone please help?
Thank you!
The error you receive makes perfect sense with your error description. The server isn't responding with the right format and therefor your client breaks.
The same error is discussed here:
nusoap simple server
You need to point the client constructor to your wsdl file...
$client = new soapclient('http://localhost/beehive/server.php');