I am not an accomplished Perl hacker and something has been frustrating me at work for the last several weeks. If you know of an easy way to solve this, I will be forever in your debt:
We are using Perl to run a HTTP server (HTTP::Daemon, incidentally, works like a charm) to receive information from a rich client application. The client has to upload text files via HTTP post. Everything is A-OK on the client’s side of things, but I have no clue how to go about extracting the uploaded text file from the HTTP request on the server side of things. My experiments have been a bunch of failures, I can’t seem to find any CPAN Module which will do this cleanly, and there are other deliverables up in the air which are getting held up by the server being only 98% complete (that last pesky 2% is critical to testing the client application, sadly). Does anyone have any suggestions? Perl’s documentation is, well… up to its usual standard of lucidity.
I would help if you were using PHP :(
If you’re trying to upload data from a client to a server over http, look into XML-RPC. You can implement an xmlrpc server that listens on port 80 that your client can upload data to.
From the xml-rpc homepage:
It’s remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.
We actually are using XML-RPC in a different portion of the project. Unfortunately, we are already more-or-less committed to using the server code which we have (i.e. Perl and HTTP transfer), since retooling it would more or less involve a rewrite (the server has no business logic on it, its essentially just for data transfer between clients).
HTTP::Request::Params is what you want. It does exactly what you want:
my $d = HTTP::Daemon->new(LocalPort => 80);
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
if ($r->method eq ‘POST’) {
my $params = HTTP::Request::Params->new({req => $r})->params;
$params is now a ref to a hash that contains all the key/value pairs you need, including the content of any uploaded files.
I could kiss you.
Luckily, I’m on the other side of the ocean from you… :)