php: Send xml/soap to Secured Server

Posted: March 11th, 2009 | Author: | Filed under: php | Tags: , , , , | 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;
}
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Address Standardization & Verification with USPS web tools and PHP
  2. Simple php ftp download file script example
  3. Create Blank Page for WordPress Blog Using Your Theme Template
  4. jQuery and php Progressive Form Example

One Comment on “php: Send xml/soap to Secured Server”

  1. 1 Technology » Blog Archive » Joe Riggs Bloggs » Blog Archive » Php: Send Xml/Soap To Secured Server said at 12:14 am on April 9th, 2009:

    [...] $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; } …Continue [...]