Creating a SOAP Request Using PHP/CURL with Password

Creating a SOAP request is great for debugging/testing a product. It seems to be difficult though to find a clean and simple code example on Google for some reason. You end up needing to look at several sites and piece it together. To many this process easier, here is a very basic SOAP request using PHP with cURL.

Be sure to set your server URL and username/password, if you’re using one. If your server doesn’t require authentication, you can comment out the CURLOPT_HTTPAUTH line.

$data = '<soapenv:Envelope xmlns:soapenv="" xmlns:urn="urn:sungardhe:enterprise:ar:messages">

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; charset=utf-8", "Content-Length: " . strlen($data)));
$output = curl_exec($ch);

echo $output . "\n";


Leave a Reply