I’m quite stuck in how to edit this script be able to take a request from jquery and return to me the value the script returns? Any help is most gratefully appreciated?
I can use it to pass an xml file and url from the filesystem and get the return I expect but would really like to be able to use it as a proxy to a wsdl service.
[edit] Due to environmental changes I’m wanting to use the below script to pass back to me the xml return from a wsdl service that I’m passing xml. It works fine when I do so from the command line – I’m just unsure how to be able to get the script to accept a post and then return the xml return from the service call.
I’m using the script as follows from the command line:
php file.php theurl <test.xml
^^ Which returns to me the xml I would like to then pass back to the frontend
<?php
ini_set('display_errors', "1");
$url= $argv[1];
echo "url\n$url\n";
preg_match("/https?:\/\/([^\/]*)(.*)/", $url, $matches);
$host=$matches[1];
$request=$matches[2];
$mxml=fread(STDIN,65536);
$yt =curl_init();
$header = "POST $request HTTP/1.0\r\n";
$header .= "Host: $host\r\n";
$header .= "SoapAction:";
$header .= "Content-Type: text/xml\r\n";
$header .= "Content-Length: ".strlen($mxml)."\r\n";
$header .= "Content-Transfer-Encoding: text\r\n";
$header .= "Connection-Close: close\r\n\r\n";
echo "header\n$header\n";
$header .= $mxml;
curl_setopt($yt, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($yt, CURLOPT_URL, $url);
curl_setopt($yt, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($yt, CURLOPT_RETURNTRANSFER, true);
$rxml=curl_exec($yt);
echo "sent\n$mxml\n";
echo "received\n$rxml\n";
echo curl_error($yt);
?>
Sussed it. Sorry forgot to post answer. Hopefully help someone else: