Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Sending a text file using POST

by Corion (Patriarch)
on Feb 11, 2016 at 14:53 UTC ( #1154962=note: print w/replies, xml ) Need Help??

in reply to Sending a text file using POST

$req->header('x-auth-token' => 'Token e45ttkfksj48sdfj4jd9abcdd');

Are you sure that the other side wants the header name all lowercase?


This sends the filename, not the file content. Is that what you want?

Also, if the server sends a 404, are you really, really sure that you're using the correct URL? Your URL ends with a slash, maybe you should leave that out? What other ways do you have to verify the correctness of the URL you use?

Replies are listed 'Best First'.
Re^2: Sending a text file using POST
by Anonymous Monk on Feb 11, 2016 at 14:58 UTC
    The URL is 100% correct, tried with and without the slash.
Re^2: Sending a text file using POST
by Anonymous Monk on Feb 11, 2016 at 15:16 UTC
    I need to send the file content not the file name, how do to about it, any suggestions?
Re^2: Sending a text file using POST
by Anonymous Monk on Feb 11, 2016 at 15:30 UTC
    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');

      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://1154962]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2022-05-18 10:03 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (70 votes). Check out past polls.