php: Send xml/soap to Secured Server
Posted: March 11th, 2009 | Author: jriggs | Filed under: php | Tags: payload, php, post, secure, xml | 1 Comment »Sample requires curl see code below:
function callWebServicePost($host, $url, $payload, $user, $password) { $header[] = "Host: ". $host; $header[] = "Content-type: text/xml"; $header[] = "Content-length: ".strlen($payload) . "\r\n"; $header[] = $payload; $session = curl_init($url); // Tell curl to use HTTP POST curl_setopt ($session, CURLOPT_POST, true); curl_setopt($session, CURLOPT_CONNECTTIMEOUT,30); // Tell curl that this is the body of the POST curl_setopt ($session, CURLOPT_POSTFIELDS, ''); // Tell curl not to return headers, but do return the response curl_setopt($session, CURLOPT_HEADER, true); // Display headers curl_setopt($session, CURLOPT_VERBOSE, true); // Display communication with server curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Return data instead of display to std out curl_setopt($session, CURLOPT_HTTPHEADER, $header ); // headers from above // provide credentials if they're established if(!empty($user) && !empty($password)) curl_setopt($session, CURLOPT_USERPWD, $user . ":" . $password); // tell cURL to graciously accept an SSL certificate if presented if(ereg("^(https)",$url)) curl_setopt($session, CURLOPT_SSL_VERIFYPEER,false); $result = curl_exec($session); curl_close($session); return $result; }