Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

parse multipart/form-data into a hash structure

by pg (Canon)
on Oct 04, 2005 at 22:53 UTC ( #497428=snippet: print w/replies, xml ) Need Help??
Description:

This sub takes a HTTP::Request, and returns a hash data structure that contains all form fields. If you have a form field named "blah", and the returned hash is stored in $form_data, then you can get the value for blah through $form_data->{"blah"}.

The asumption is that the form use multipart/form-data encoding. The code is something I use, and not heavily tested with differnt situations.

sub analyze_request {
    my $req = shift;
    my $form_data;
    for my $part ($req->parts()) {
        if (my $content_disposition = $part->headers->header("Content-
+Disposition")) {
            if ($content_disposition =~ /^form-data; name=\"(.*?)\"/) 
+{
                $form_data->{$1} = $part->content();
            }
        }
    }
    return $form_data;
}
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://497428]
help
Chatterbox?
[karlgoethebier]: marioroy: Racket ball is considered harmful, like Squash
[marioroy]: Wait till folks see what MCE::Hobo can do in the upcoming release. Multiple instances, nested spawning, 3 levels, doesn't matter. it works on Windiows too.
[Lady_Aleena]: I hate sites that tell me to turn ad-blocker off. They should know better.
[marioroy]: s/Windiows/ Windows/
[Discipulus]: marioroy can you expand that Niagara's fall history?
erix only sees fallen angels
erix if it weren't for bad luck, I'd have no luck at all
Discipulus Windiows the OS of native americans..
[karlgoethebier]: marioroy: Next step: Write the ultimate book. "Parallel Programming With Perl. Yet Another Missing Manual" ;-)
[marioroy]: karlgoethebier I do not do Racket ball anymore. That was from gym class long ago.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-05-29 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?