title: How to properly send and receive XML using curl?
body: <p>I've been trying to post XML and get response from the server but with no luck.</p>
  
  <p>Here are the conditions on server side:</p>
  
  <ul>
  <li>Requests to the server should be sent as XML over HTTP 1.1.</li>
  </ul>
  
  <p>The following requirements apply to the HTTP request:</p>
  
  <ul>
  <li>The request type should be POST;</li>
  <li>A <code>Content-Length</code> header should be present, and the total length of the request should be below 16KB;</li>
  <li>A <code>Content-Type</code> header should be present, containing the media type value <code>text/xml</code>;</li>
  </ul>
  
  <p>Here is my script:</p>
  
  <pre><code>$url = "http://somedomain.com";
  $xml = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Request PartnerID="asasdsadsa" Type="TrackSearch"&gt; &lt;TrackSearch&gt; &lt;Title&gt;love&lt;/Title&gt;    &lt;Tags&gt; &lt;MainGenre&gt;Blues&lt;/MainGenre&gt; &lt;/Tags&gt; &lt;Page Number="1" Size="20"/&gt; &lt;/TrackSearch&gt; &lt;/Request&gt;';
  $header  = "POST HTTP/1.1 \r\n";
  $header .= "Content-type: text/xml \r\n";
  $header .= "Content-length: ".strlen($xml)." \r\n";
  $header .= "Connection: close \r\n\r\n"; 
  $header .= $xml;
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
  $data = curl_exec($ch); 
  echo $data;
  if(curl_errno($ch))
      print curl_error($ch);
  else
      curl_close($ch);
  </code></pre>
  
  <p>This gives me:</p>
  
  <pre><code> HTTP Error 400. The request URL is invalid.
   Bad Request - Invalid URL
  </code></pre>