title: How to post the content of a file using Perl Script
body: <p>I am very new to Perl and badly needing for help.
  I have a file.txt where I want to post its content to a webservice url.</p>
  
  <p>This is the sample of my file.txt content.</p>
  
  <pre>
  Name: name1
  Address: address1
  
  Name: name2
  Address: address2
  
  Name: name3
  Address: address3
  </pre>
  
  <p>And here it my post.pl (referencing from this site: <a href="http://xmodulo.com/how-to-send-http-get-or-post-request-in-perl.html" rel="nofollow">http://xmodulo.com/how-to-send-http-get-or-post-request-in-perl.html</a>)</p>
  
  <pre><code>#!/usr/bin/perl
  use warnings;
  use strict;
  use LWP::UserAgent;
  
  my $ua = LWP::UserAgent-&gt;new;
  my $url = "https://domain/post.php";
  
  # set custom HTTP request header fields
  my $req = HTTP::Request-&gt;new(POST =&gt; $url);
  $req-&gt;content_type('application/json');
  
  # add POST data to HTTP request body
  my $post_data = '{"name":"myName", "address":"myAddress"}'; // I want to post here the content of file.txt
  $req-&gt;content($post_data);
  print $req-&gt;as_string;
  my $resp = $ua-&gt;request($req);
  
      if ($resp-&gt;is_success) {
      my $message = $resp-&gt;decoded_content;
         print "\nReceived reply: $message\n";
     }
     else {
         print "HTTP POST error code: ", $resp-&gt;code, "\n";
         print "HTTP POST error message: ", $resp-&gt;message, "\n";
     }
  </code></pre>
  
  <p>Using above file and script, how can I possible post the contents of the file.
  Thank you in advance.</p>