title: How to send xml file content to webservice using php curl
body: <p>I have a datafile.xml that needs to be sent to a webservice.
  I am using php curl to send the file.  The problem is I don't know how to access and send the contents of the datafile.xml.</p>
  
  <p>Here is content of the datafile.xml -</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;inventoryUpdateRequest version="1.0"&gt;
  &lt;action name="bookupdate"&gt;
  &lt;username&gt;user&lt;/username&gt;
  &lt;password&gt;issecret&lt;/password&gt;
  &lt;/action&gt;
  &lt;WebList&gt;
  &lt;Website&gt;
  &lt;transactionType&gt;delete&lt;/transactionType&gt;
  &lt;vendorBookID&gt;FaNuPh1&lt;/vendorBookID&gt;
  &lt;/Website&gt;
  &lt;/WebList&gt;
  &lt;/inventoryUpdateRequest&gt;
  </code></pre>
  
  <p>Here is my send php file -</p>
  
  <pre><code>&lt;?php require_once('post_xml.php');?&gt;
  &lt;?php 
  
  $xml = HERE IS MY LACK OF UNDERSTANDING HOW TO EXTRACT datafile.xml CONTENT;
  
  $url ='https://inventoryupdate.website.com';
  $port = 80;
  $response = xml_post($xml, $url, $port);    
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;P&gt;&lt;?=nl2br(htmlentities($response));?&gt;&lt;/P&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is the post_xml.php file that uses cURL -</p>
  
  <pre><code>&lt;?php
  // open a http channel, transmit data and return received buffer
  function xml_post($post_xml, $url, $port)
  {
  $user_agent = $_SERVER['HTTP_USER_AGENT'];
  
  $ch = curl_init();    // initialize curl handle
  curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);              // Fail on errors
  
  if (ini_get('open_basedir') == '' &amp;&amp; ini_get('safe_mode' == 'Off'))
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    // allow redirects
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
  curl_setopt($ch, CURLOPT_PORT, $port);          //Set the port number
  curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
  curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  
  if($port==443)
  {
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  }
  
  $data = curl_exec($ch);
  
  curl_close($ch);
  
  return $data;
  }
  ?&gt;
  </code></pre>
  
  <p>Any help would be much appreciated!</p>