Monday, May 9, 2016

Sending SOAP or MIME Messages from PHP

If you have well formatted SOAP or MIME messages, here's a simple PHP script that allows you to do so. The function returns the reply from the server.
  1. //----------------------------------------------------------------- execCurl --  
  2. function execCurl($url$header$query)  
  3. {  
  4.     $ch = curl_init();  
  5.     curl_setopt($ch, CURLOPT_URL,            $url);  
  6.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  7.     curl_setopt($ch, CURLOPT_HTTPHEADER,     $header);  
  8.     curl_setopt($ch, CURLOPT_POSTFIELDS,     $query);  
  9.     $r = curl_exec($ch);  
  10.     if (curl_errno($ch)) {  
  11.         echo curl_error($ch);  
  12.         exit(1);  
  13.     }  
  14.     curl_close($ch);  
  15.     return $r;  
  16. }  

No comments:

Post a Comment