Sometimes there is a need to send a simple HTTP Post request. You can use curl but with Perl you can easily parse the data from the server response.

To use it, you will probably need to install libwww-perl with your system package manager.

In this case we are changing our UserAgent string, we are also adding an additional header to the request. We are telling LWP that we will also accept redirects after our POST request is done and finally we are making the request itself and getting the data(if the answer was "200 OK") or the status code(in case of any other status code).

use LWP::UserAgent;

my $ua = LWP::UserAgent->new(timeout => 10);
$ua->env_proxy;
$ua->agent('Mozilla/5.0');
$ua->default_header('X-Sender' => "Perl");

push @{ $ua->requests_redirectable }, 'POST';

my $response = $ua->post('http://opsec.fr/send', ["User"=> "a", "Pass"=> "b"]);

if ($response->is_success) {
print $response->decoded_content;
}
else {
die $response->status_line;
}