title: How to force XML response using PHP CURL
body: <p>I am testing an XML API which is successfully hitting my account and I am getting a response, but the response appears to be a plain text string with no tags or anything, not even name/pair values. I need the response to be captured as XML so I can use the XML tags to identify the response variables.</p>
  
  <p>I use a form POST to communicate the data from the form to the CURL page which parses the POST into XML format then uses CURL to send it to the API. The API is XML based an I expect an XML response, but instead receive </p>
  
  <p>HELPS!</p>
  
  <p><b> CURL REQUEST/RESPONSE PAGE </b></p>
  
  <pre><code>                        &lt;?php
                      if ($_SERVER['REQUEST_METHOD'] == 'POST') 
                      {
                          $xml = "&lt;?xml version='1.0' encoding='UTF-8'?&gt;";
                          $xml .= "&lt;request&gt;";
  
                          foreach ($_POST as $key =&gt; $val) {
                              $xml .= "&lt;".$key."&gt;". $val ."&lt;/".$key."&gt;";
                          }
                          $xml .= "&lt;username&gt;user1234&lt;/username&gt;";
                          $xml .= "&lt;password&gt;pass1234&lt;/password&gt;";
                          $xml .= "&lt;/request&gt;";               
  
                          echo "&lt;br/&gt;" . $xml . "&lt;br/&gt;&lt;br/&gt;";
  
                          $ch = curl_init();
                          curl_setopt($ch, CURLOPT_URL, 'https://www.beanstream.com/scripts/process_transaction.aspx');
                          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
                          curl_setopt($ch, CURLOPT_HEADER, 1);
                          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
                          curl_setopt($ch, CURLOPT_POST, 1);
                          curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  
                          $output = curl_exec($ch);
                          curl_close($ch);
  
                          print_r($output);       
                      }
                      ?&gt;
  </code></pre>
  
  <p><b> API RESPONSE <i>with header</i> </b></p>
  
  <pre><code>HTTP/1.1 200 OK Cache-Control: private Content-Length: 724 Content-Type: application/xml; charset=utf-8 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Set-Cookie: ASP.NET_SessionId=1p4jp2uoz2de3f45iolold3j; path=/; HttpOnly Date: Wed, 16 Oct 2013 21:39:38 GMT 1100001211ApprovedQCE9HW5ETESTNT53.4810/16/2013 2:39:38 PM1W001Postal/ZIP matches, street address does not match.1VIPCC7
  </code></pre>