seamonk has asked for the wisdom of the Perl Monks concerning the following question:

im trying to rebuild a request (File upload), the packed send from the webbrowser looks like this:
-----------------------------596088922920 Content-Disposition: form-data; name="Filedata"; filename="mypic.gif" Content-Type: image/gif GIF87aX# *shorted* ¡§\ -----------------------------596088922920 Content-Disposition: form-data; name="session" 92384729384792384729384729384 -----------------------------596088922920 Content-Disposition: form-data; name="method" put -----------------------------596088922920--
my per code looks like this:
use WWW::Mechanize; $agent = WWW::Mechanize->new( cookie_jar => {} ); $agent->post('http://www.kleiderkreisel.de/photo/ajax_photo_action', [ "Filedata" => ['mypic.gif' => 'C:\Pics\mypic.gif'], 'session' => '92384729384792384729384729384', 'method' => 'put' ]);
sadly this gives me the error "Internal Server Error"... What am i doing wrong?

Replies are listed 'Best First'.
Re: Error POSTing File in Perl
by thomas895 (Deacon) on Aug 16, 2014 at 19:38 UTC

    The documentation for WWW::Mechanize specifies that the post method is inherited from that of LWP::UserAgent, which specifies that for advanced things you should see HTTP::Request::Common.
    We know that to upload a file via a form, one must specify a Content-Type header of multipart/form-data. Use your browser's search function to find that string, and read that section.

    We have now learned that we must also set that header ourselves. Using that information, set this header in your $agent in the usual manner.

    HTH,

    ~Thomas~ 
    "Excuse me for butting in, but I'm interrupt-driven..."
Re: Error POSTing File in Perl
by linuxer (Curate) on Aug 17, 2014 at 09:42 UTC
Re: Error POSTing File in Perl (PUT)
by Anonymous Monk on Aug 17, 2014 at 09:15 UTC

    Hi, good luck on your investigation

    sadly this gives me the error "Internal Server Error"... What am i doing wrong?

    You're trying to replay a session for starters :) servers are free to be insane :)

    Also you're using post for PUT request, use put for put request :)

    Also, you're not retrieving the request you sent or tried to send from mech ... see what you tried to send to server, its Basic debugging checklist

    Try HTTP::Parser::XS / Plack::HTTPParser::PP - Pure perl fallback of HTTP::Parser::XS

    Along with HTTP::Body, its what Plack::Request uses

    Between those modules you can build yourself a HTTP::Request you can $mech->request( $req );

    Maybe See also HTTP::Request::StreamingUpload

    Good luck seamonk

      Also you're using post for PUT request, use put for put request
      it's not actually impossible that the webserver is indeed expecting a POST request with a "method" parameter whose value is "put"; or, at least, I've seen sillier things.
Re: Error POSTing File in Perl
by GwenDragon (Novice) on Aug 18, 2014 at 09:47 UTC

    If you get a Error 500 the web server has a problem with your data or a temporary mailfunction.

    You did not mention you asked StackOverflow at http://stackoverflow.com/questions/25341815/error-posting-file-in-perl

    Your URL in code is nonexistent on the webserver. It's not very helpful posting fake URLs from existing websites and asking for help with code which can not work in reality.
    =:/