Hello Monks, Hope you are well!
I am attempting to POST a text file to a local server, using port 8012.
I have been trying to do this using LWP::UserAgent. The main example I have been trying is found here.
Based on the example, I have produced the following code:
my $ua = LWP::UserAgent->new;
my $res = $ua->post('http://localhost:8012/',
Content_Type => 'form_data',
Content => [
Filedata => [ 'Hello.txt', 'Hello.txt',
Content_Type => 'text/plain',
],
submit => 'Submit',
],
);
if ($res->is_success) {
print $res->content;
} else {
print $res->status_line, "\n";
}
To get more specific about the codes purpose: I am running a docker container on a server that is communicated with via port 8012. The goal is to send a file here, process it and then return the
body of the processed file.
When I use Postman to submit the file via POST request, it works as expected: The server gets the file, processes it, and returns the body of the desired output file.
When I run the above code, I get "TypeError: Cannot read property 'end' of undefined" on the server end, and the output from the program is '500 Server closed connection without sending any
data back'.
This is my first time doing any of this sort of thing, so any tips, solutions, and critiques are obviously welcome!
cookersjs
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.