Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use Data::Dumper; my $ua = LWP::UserAgent->new(); my $server_endpoint = "https://www.tothesite.com/place/44498/"; # set custom HTTP request header fields my $req = HTTP::Request->new(POST => $server_endpoint); $req->headers(); print Dumper( $req->headers() ); $req->header('x-auth-token' => 'Token e45ttkfksj48sdfj4jd9abcdd'); # add POST data to HTTP request body my $filename = "/var/www/location/first_text.txt"; $req->content($filename); my $resp = $ua->request($req); if ($resp->is_success) { my $message = $resp->decoded_content; print "Received reply: $message\n"; }else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sending a text file using POST
by Corion (Patriarch) on Feb 11, 2016 at 14:53 UTC | |
by Anonymous Monk on Feb 11, 2016 at 15:16 UTC | |
by Anonymous Monk on Feb 11, 2016 at 15:30 UTC | |
by Corion (Patriarch) on Feb 11, 2016 at 16:05 UTC | |
by Anonymous Monk on Feb 11, 2016 at 16:31 UTC | |
by Anonymous Monk on Feb 11, 2016 at 14:58 UTC | |
Re: Sending a text file using POST
by choroba (Cardinal) on Feb 11, 2016 at 15:27 UTC |