Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Sending a text file using POST

by Anonymous Monk
on Feb 11, 2016 at 15:30 UTC ( #1154968=note: print w/replies, xml ) Need Help??

in reply to Re: Sending a text file using POST
in thread Sending a text file using POST

I updated the code to read the file content using "File::Slurp".
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use File::Slurp; use Data::Dumper; my $ua = LWP::UserAgent->new(); my $server_endpoint = ""; # 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 = "first_text.txt"; my $data_file = read_file( $filename, { binmode => ':raw' } ); $req->content($data_file); 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"; }

Now I am getting this error:
HTTP POST error code: 500
Do you know if this line is code syntax correct?
 $req->header('x-auth-token' => 'Token e45ttkfksj48sdfj4jd9abcdd');

Replies are listed 'Best First'.
Re^3: Sending a text file using POST
by Corion (Patriarch) on Feb 11, 2016 at 16:05 UTC

    I don't know. Maybe the documentation of the endpoint you're talking to has more information on what it expects?

      I even added this line before the "header":
      And still an error; multi-part form data parse error.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154968]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-05-17 08:48 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (65 votes). Check out past polls.