title: Send a HTTP POST Request(xml data ) using WWW::Curl in perl
body: <p>I want to use <code>WWW::Curl</code> instead of <code>LWP::UserAgent</code> to send a post request.
   Below is the Code using <code>LWP::UserAgent</code> which works fine. </p>
  
  <pre><code>my $agent = LWP::UserAgent-&gt;new(agent =&gt; 'perl post');
  push @{ $agent-&gt;requests_redirectable }, 'POST';
  my $header  = HTTP::Headers-&gt;new;
  $header-&gt;header('Content-Type'  =&gt; "text/xml; charset=UTF-8");
  $header-&gt;content_encoding('gzip');
  utf8::encode( my $utf8_content = $args{content} );
  sinfo $utf8_content;
  $error-&gt;description($utf8_content);
  $error-&gt;log;
  my $request = HTTP::Request-&gt;new(POST =&gt; $args{url}, $header, $utf8_content);
  my $response = $agent-&gt;request($request);
  </code></pre>
  
  <p>I need to rewrite this code using WWW::Curl as Curl is faster than LWP.
     I have tried the below code but it returns me code '35' as response, which 
     means the request is invalid.</p>
  
  <pre><code>my $curl = WWW::Curl::Easy-&gt;new();
  
  $curl-&gt;setopt(WWW::Curl::Easy::CURLOPT_HEADER,1);
  $curl-&gt;setopt(WWW::Curl::Easy::CURLOPT_URL,$self-&gt;uri());
  $curl-&gt;setopt(WWW::Curl::Easy::CURLOPT_POST, 1);
  $curl-&gt;setopt(WWW::Curl::Easy::CURLOPT_POSTFIELDS, $utf8_content);
  
  my $response;
  
  $curl-&gt;setopt(WWW::Curl::Easy::CURLOPT_WRITEDATA,\$response);
  
  my $retcode = $curl-&gt;perform();
  </code></pre>
  
  <p>The data i pass in the post request ($utf8_content) is a xml string ,sample xml :</p>
  
  <pre><code>   &lt;Request&gt;
       &lt;Source&gt;
         &lt;RequestorID Password="PASS" Client="Client" EMailAddress="email@address.com"/&gt;
         &lt;RequestorPreferences Language="en"&gt;
           &lt;RequestMode&gt;SYNCHRONOUS&lt;/RequestMode&gt;
         &lt;/RequestorPreferences&gt;
       &lt;/Source&gt;
       &lt;RequestDetails&gt;
         &lt;SearchRequest&gt;
           &lt;ItemDestination DestinationType="area" DestinationCode="XYZ"/&gt;
           &lt;/ItemDestination&gt;
         &lt;/SearchRequest&gt;
       &lt;/RequestDetails&gt;
     &lt;/Request&gt; 
  </code></pre>
  
  <p>Moreover  the response too will be a xml string which can be retrieved from $response;</p>