code_junkie

PHP4: Send XML over HTTPS/POST via cURL?

Nov 11th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. /**
  2. * Send XML via http(s) post
  3. *
  4. * curl --header "Content-Type: text/xml" --data "<?xml version="1.0"?>...." http://www.foo.com/
  5. *
  6. */
  7. function sendXmlOverPost($url, $xml) {
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_URL, $url);
  10.  
  11. // For xml, change the content-type.
  12. curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
  13.  
  14. curl_setopt($ch, CURLOPT_POST, 1);
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  16.  
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned
  18. if(CurlHelper::checkHttpsURL($url)) {
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  20. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  21. }
  22.  
  23. // Send to remote and return data to caller.
  24. $result = curl_exec($ch);
  25. curl_close($ch);
  26. return $result;
  27. }
  28.  
  29. if( $this -> usingHTTPS() )
  30. {
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  32. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->sslVerifyHost);
  33.  
  34. }
  35.  
  36. curl_setopt($ch,CURLOPT_POST,TRUE);
  37. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  38. curl_setopt ($ch, CURLOPT_POSTFIELDS, "OTA_request=".urlencode($this->xmlMessage));
  39.  
  40. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  41.  
  42. $this->xmlResponse = curl_exec ($ch);
  43.  
  44. $this -> callerFactory -> dbgMsg('xmlResponse: <hr><pre>'.htmlentities($this->xmlResponse).'</pre><hr>'. curl_error($ch));
  45. curl_close ($ch);
  46.  
  47. $this->checkResponse();
  48.  
  49. $soap = new SoapClient("http://some.url/service/some.wsdl");
  50. $args = array("someTypeName" => "someTypeValue"
  51. "someOtherTypeName" => "someOtherTypeValue");
  52.  
  53. $response = $soap->executeSomeService($args);
  54.  
  55. print_r($response);
Add Comment
Please, Sign In to add comment